Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

Scenario 4: Form for performing Ingestion of Multiple Files with Single Transaction

Scenario 4: Form for performing Ingestion of Multiple Files with Single Transaction

  • Last UpdatedJan 10, 2024
  • 7 minute read

This scenario shows how you can create a form with multiple Tabs having PanelForm container containing a Grid control and use it in the workflow which uses single transaction for performing ingestion of multiple files with single Ingestion Activity.

Designing a Form with three tabs, each tab containing a PanelForm Container, each panelform containing a Grid control. Then using the Form API skelta.grid.saveGridDataToCloudStorage to upload the Grid Data to Aveva Cloud Storage and using the returned filename to use it In the Workflow with Ingestion Activity. Workflow is designed with Single Ingestion Activity executed within a loop which uses a Single Transaction.

You can create a form with three tabs, each consisting of a PanelForm Container with a Grid control. Utilize Form API skelta.grid.saveGridDataToCloudStorage to upload Grid Data to AVEVA Cloud Storage. Use the returned filename in a Workflow with a single Ingestion Activity executed in a loop within a single transaction.

Two new properties are added to the Ingestion Activity.

  • Transaction Id - Transaction Id to be used for the Ingestion Activity. If it is empty it will create a new Transaction while executing the Ingestion Activity. 

  • Complete Transaction - To complete the transaction or not. By default the value of the property is True.

To design a Form for ingestion of multiple files with single transaction

  1. Create a Form and name it as FormForMultipleFilesIngestion.

  2. Set the property Show Save Button as No for the Form.

  3. Drag three Tab containers into the Form.

  4. In each of the three Tab containers, create a Tab control and name it as CustomerDetails, OrderDetails, and InvoiceDetails respectively.

  5. Inside each of the three Tab controls (CustomerDetails, OrderDetails, and InvoiceDetails), drag a PanelForm container and name it as PanelForm1, PanelForm2, and PanelForm3 respectively. For each PanelForm container set the property Show Panel Details as No.

  6. Inside each of the three PanelForm containers (PanelForm1, PanelForm2, and PanelForm3), drag the following controls:

    1. TextBox controls and name it as Source1, Source2, and Source3 for each container respectively.

    2. DataGrid controls and name it as CustomerDetailsGrid, OrderDetailsGrid, and InvoiceDetailsGrid for each container respectively. Configure each of the DataGrid controls and set the property All Pages as Yes.

    3. TextBox controls and name it as ExportedFileName1, ExportedFileName2, and ExportedFileName2 for each container respectively.

  7. Drag a Button control into the Form and name it as Process.

    Embedded Image (65% Scaling) (LIVE)

    On Click Script for the Process Button

    var sources=[{"gridObject":control.findByXmlNode("CustomerDetailsGrid"), "fileName":"CustDet.XlSx"},

    {"gridObject":control.findByXmlNode("OrderDetailsGrid"), "fileName":"OrderDet.xlsx"},

    {"gridObject":control.findByXmlNode("InvoiceDetailsGrid"), "fileName":"InvoiceDet.xlsx"},

    ];

    var targetControl=[control.findByXmlNode("ExportedFileName1"),control.findByXmlNode("ExportedFileName2"),control.findByXmlNode("ExportedFileName3")];

    var ignoreEmptyGridDataValidation = false;

    SFU.showLoader();

    skelta.grid.saveGridDataToCloudStorage(sources, ignoreEmptyGridDataValidation)

    .then(function(results){

    var errorMessages="";

    $.each(results,function(index,item)

    {

    if(SFU.isUndefined(item.fileName) || item.fileName=="")

    {

    if(!SFU.isUndefined(item.error))

    {

    if(errorMessages.length>0)

    {

    errorMessages += "<br>";

    }

    errorMessages += item.error.replaceString("\n","<br>");

    }

    else

    {

    targetControl[index].value= "";

    }

    }

    else

    {

    targetControl[index].value=item.fileName;

    }

    });

    if(errorMessages.length>0)

    {

    SFU.hideLoader();

    SFU.showError(document.title, errorMessages);

    }

    else

    {

    control.submitForm(event);

    }

    });

  8. Publish the Form.

  9. Go to the Forms List and select Associate from the context menu for the above form.

  10. In the Form Binding screen, select Design a new workflow and click Next button.

  11. Enter the Title for the Workflow as ScenarioForMultipleFilesIngestionWF in the New Workflow screen

  12. Click Save & Continue button. On success message screen, click Ok button.

  13. On Workflow Tasks screen, select Design the Workflow now option and click Finish button.

    The Process Designer screen opens to design the workflow.

You can design the workflow to perform ingestion for multiple files with maintaining single transaction in below two ways:

  • Using Multiple Ingestion Activities

  • Using Single Ingestion Activity

Using Multiple Ingestion Activities

  1. Drag the Ingestion Activity from the Integration Activity category.

  2. Set the FileName property for the activity as,

    <%#XmlVariables.SFFormData.SKRootDefinition.Panelform1.ExportedFileName1%>

  3. Set the Source property as,

    <%#XmlVariables.SFFormData.SKRootDefinition.Panelform1.Source1%>

  4. Set the Transaction Id property as blank for the first Ingestion Activity.

  5. Set the Complete Transaction property to false for the first Ingestion Activity.

  6. In the Start activity declare the variables as,

    ^Ingestion Activity1TransactionId

    ^Ingestion Activity1ServiceResponse

  7. Drag the second Ingestion Activity from the Integration Activity category.

  8. Link the first Ingestion Activity with the second Ingestion Activity with the link output of Successful.

  9. Set the FileName property for the Activity as,

    <%#XmlVariables.SFFormData.SKRootDefinition.Panelform1.ExportedFileName2%>

  10. Set the Source property as,

    <%#XmlVariables.SFFormData.SKRootDefinition.Panelform1.Source2%>

  11. Set the Transaction Id property based on the First Ingestion Activity system variable as,

    <%#Variable.^Ingestion Activity1TransactionId%>

  12. Set the Complete Transaction property to false for the second Ingestion Activity.

  13. Drag the third Ingestion Activity from the Integration Activity Category.

  14. Link the second Ingestion Activity with the third Ingestion Activity with the link output of Successful.

  15. Set the FileName Property for the Activity as,

    <%#XmlVariables.SFFormData.SKRootDefinition.Panelform1.ExportedFileName3%>

  16. Set the Source property as,

    <%#XmlVariables.SFFormData.SKRootDefinition.Panelform1.Source3%>

  17. Set the Transaction Id property based on the first Ingestion Activity system variable as,

    <%#Variable.^Ingestion Activity1TransactionId%>

  18. Set the Complete Transaction property to true for the third Ingestion Activity.

  19. Design of the workflow as below.

    Using Single Ingestion Activity

    1. Declare the following Variables in the Start Activity:

      1. VarPanelFormCount – Number

      2. VarFileNameArray – array

      3. VarSourceArray – array

      4. VarFileName – string

      5. VarSource – string

      6. VarCompleteTransaction – bool

      7. intLoopVariable – number

      8. intTotalLoopCount – number

      9. ^MultipleFilesIngestionTransactionId – string

      10. ^MultipleFilesIngestionServiceResponse - string

      Embedded Image (65% Scaling) (LIVE)

    2. Update the VarPanelFormCount Variable value through Initialize VAriable(s) property in the Start Activity based on the number of panel forms in the Designed form. In this Example, the Form is designed with three PanelForms.

      Embedded Image (65% Scaling) (LIVE)

    3. Drag a Script Activity after the start activity and name it as GetFileNameandSource

      1. Set the Language as CSharp.Net

      2. Enter the code text as below in the Code property.

        using System;
        using System.Collections;
        using System.Xml;
        using Workflow.NET;
        using Workflow.NET.Engine;

        public class WorkflowScript61092250167a4eb297eb3890bc7e3b6b
        {
        public string Run(int ExecutionId, int ExecutionDetailsId, Workflow.NET.Engine.Context ctx, Workflow.NET.Action action, string inlink)
        {
        XmlVariable xmlVar = ctx.XmlVariables["SFFormData"];
        var xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xmlVar.RawXml);
        var totalCnt = Convert.ToInt32(ctx.Variables["VarPanelFormCount"].Value);
        ArrayList arrFileNames = new ArrayList();
        ArrayList arrSourceNames = new ArrayList();
        for (int i = 1; i <= totalCnt; i++)
        {
            var xPath = "Panelform" + i;

            foreach (XmlNode nodes in xmlDoc.DocumentElement.SelectNodes("//SKRootDefinition/" + xPath))
            {
                var fileNameXmlNode = nodes.SelectSingleNode("ExportedFileName" + i);
                var sourceXmlNode = nodes.SelectSingleNode("Source" + i);
                if (!string.IsNullOrWhiteSpace(fileNameXmlNode.InnerText))
                {
                    if (ctx.Variables["VarFileNameArray"].Value != null)
                    {
                        arrFileNames = (ArrayList)ctx.Variables["VarFileNameArray"].Value;
                    }

                    arrFileNames.Add(fileNameXmlNode.InnerText);
                    ctx.Variables["VarFileNameArray"].Value = arrFileNames;

                    if (ctx.Variables["VarSourceArray"].Value != null)
                    {
                        arrSourceNames = (ArrayList)ctx.Variables["VarSourceArray"].Value;
                    }

                    arrSourceNames.Add(sourceXmlNode.InnerText);
                    ctx.Variables["VarSourceArray"].Value = arrSourceNames;
                    ctx.SaveVariables();

                }

            }
        }

        ctx.Variables["intTotalLoopCount"].Value = arrFileNames.Count;
        ctx.SaveVariables();

        return "Success";

        }

    4. Drag the For Loop Activity from the Engine Activity and connect it from Script Activity GetFileNameandSource.

      1. Set the Loop Variable as intLoopVariable

      2. Set the Loop Count as intTotalLoopCount.

    5. Drag a script Activity and name it as AssignFileNameandSource

      1. Link the script activity from For Loop with the Output Step

      2. Set the Language for the script activity as CSharp.Net

      3. Set the Code as below in the Code property.

        using System;
        using System.Collections;
        using Workflow.NET;
        using Workflow.NET.Engine;

        public class WorkflowScript226c5adbe4724df2bd7e719c6731c3ad
        {
        public string Run(int ExecutionId, int ExecutionDetailsId, Workflow.NET.Engine.Context ctx, Workflow.NET.Action action, string inlink)
        {
        var index = Convert.ToInt32(ctx.Variables["intLoopVariable"].Value) - 1;
        var loopCount = Convert.ToInt32(ctx.Variables["intTotalLoopCount"].Value);
        ArrayList arrFileNames = (ArrayList)ctx.Variables["VarFileNameArray"].Value;
        ArrayList arrSourceNames = (ArrayList)ctx.Variables["VarSourceArray"].Value;

        ctx.Variables["VarFileName"].Value = arrFileNames[index];
        ctx.Variables["VarSource"].Value = arrSourceNames[index];

        if ((index + 1) == loopCount)
        {
            ctx.Variables["VarCompleteTransaction"].Value = true;
        }
        else
        {
            ctx.Variables["VarCompleteTransaction"].Value = false;
        }

        ctx.SaveVariables();
        return "Success";

        }

      4. Set the return value as Success.

    6. Drag a Ingestion Activity and name it as MultipleFilesIngestion.

      1. Link the AssignFileNameandSource script activity to the ingestion activity with the output link as Success

        1. Set the FileName property value as <%#Variable.VarFileName%>

        2. Set the Source property value as <%#Variable.VarSource%>

        3. Set the Complete Transaction value through Expression Editor pointing to the variable VarCompleteTransaction

      2. Drag the Next Loop Activity from the Engine Activity Category.

        1. Link from the MultipleFilesIngestion Activity to the Next Loop Activity with the link output as Successful

      3. Link from the Next Loop Activity to the For Loop Activity with the link output as Next Step

        Design the Workflow as below:

        Note: If there are multiple Ingestion Activities serially in the workflow, then for the first Ingestion Activity, the Transaction Id property value should be empty and the Complete Transaction property value should be false. For the next Ingestion Activities, the Transaction Id property value should be set with the Variable "^" + ActionName of First Activity + "TransactionId" and the Complete Transaction property value should be false, except the last Ingestion Activity where Complete Transaction property value should be true.
        If you want to perform Ingestion Activity for Multiple Files with a Single Transaction, then in the workflow, Ingestion Activity must be in serial.

        Related Links
        TitleResults for “How to create a CRG?”Also Available in