Automate

 View Only
Expand all | Collapse all

How to set a field value in a repeating Table based on the entry of another field per row

  • 1.  How to set a field value in a repeating Table based on the entry of another field per row

    Posted 03-18-2024 11:15

    Hi, 

    I am trying to set a field value automatically in a repeating table based on another field in the same row. 

    If the Material description contains Subst. set availability check to CH if materials description does not contain Subst. set availability check to YS.

    Currently the rule checks only the Material description in the first row of the table and sets for all rows the same value for the availability check. 

    What do to make sure that the rule checks the material description of each rows and sets the availability check per row to the correct value? 

    Regards, 

    Mirka



    ------------------------------
    Mirka Ploemen
    Process Controller
    Smurfit Kappa Group plc
    Roermond
    ------------------------------


  • 2.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Posted 03-18-2024 12:14

    Hi Mirka,

    that's something I would do with an Excel formula in the availabililty check column on the uploadfile, the formula would look like =IF(NOT(ISERROR(FIND("Subst.",column-row))),"CH","YS"), where column-row would point at the description location in that row.

    hth, jan



    ------------------------------
    jan ketele
    release expert
    Xeikon Manufacturing NV
    ------------------------------



  • 3.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Employee
    Posted 03-18-2024 13:52

    Hi Mirka,

    If your question is related to form solutions, then you can use javascript code to loop through all rows and set the value.

    please find an example attached in link : https://nowtransfer.de/733b2d2cb5ce

    in the solution upload the excel data provided in within the link, If the field value contains 'DESC' it sets field_2 to 'CH' else it sets it to 'YS'.

    Javascript code is applied on field_1 on the form as a custom rule.

    Hope this Helps.

    Regards



    ------------------------------
    Hammad Naeem
    Precisely Software Inc.
    ------------------------------



  • 4.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Employee
    Posted 03-18-2024 16:52

    Hi Mirka,

    Question for you.  How is the table data populated?  If you type it, then it should trigger.  But if it's filled from a data source or Query script, then rules don't always get triggered when you think they will.  

    A couple of ways to trigger rules on rows populated non-manually:

    • Use a "helper field", a value that isn't displayed but is at the row level. So you could change the value of the helper field, which could then trigger your rule to check the description.  You want all of the fields in that rule to be at the row level to work properly.
    • Use a rule on your data to run rules on MaterialDescription if the field is not blank - again - trigger at the row level:
    • if all else fails, you can use Javascript  - Hammad has shared an example, and you can also convert your rule to Javascript and try it

    Hope that helps,

    Sigrid



    ------------------------------
    Sigrid Kok
    Precisely Software Inc.
    ------------------------------



  • 5.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Posted 03-20-2024 09:41

    Hallo Sigrid, 

    I am copying the Material number and Description from another table into this table by using a button. I have another button which sets some values of other fields and also this rule was added to that button. I have absolutely no experience with Java script but will try if I get it to work with a helper field. 

    Regards, 

    Mirka



    ------------------------------
    Mirka Ploemen
    Process Controller
    Smurfit Kappa Group plc
    Roermond
    ------------------------------



  • 6.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Posted 03-20-2024 11:55

    Me again, what do you think about below code. Is this something which should theoretical wok and if so what could be the reason that it doesn't work?  I put this rule as a custom rule on field Material_Description_2 and execute the rule with a button.

     

    var rows = count('my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content'); // fetch number of rows in repeating table.

    for (var i = 0; i < rows; i++) {
        var materialDescription = $form.getValue('/my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content[' + i + ']/my:Material_Description_2').toString();

        if (materialDescription.contains('Subst')) {
            $form.setValue('/my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content[' + i + ']/my:Checking_Group_for_Availability_Check', "CH");
        } else {
            $form.setValue('/my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content[' + i + ']/my:Checking_Group_for_Availability_Check', "YS");
        }
    }



    ------------------------------
    Mirka Ploemen
    Process Controller
    Smurfit Kappa Group plc
    Roermond
    ------------------------------



  • 7.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Employee
    Posted 03-20-2024 12:40

    Hi Mirka,

    Line 1 in code above how you are calculating the number of rows must be throwing an error, it should changed to :

    var rows = count('my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content/my:Material_Description_2'); 

    // basically xpath of any of the field in repeating table. Rest of the code looks fine.

    Try changing this, Hope this helps.

    Regards



    ------------------------------
    Hammad Naeem
    Precisely Software Inc.
    ------------------------------



  • 8.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Employee
    Posted 03-20-2024 15:32

    Hi Mirka,

    Just tried out your code and found that 'Contains' method doesn't work, you need to use match method. So, your code should look like:

    --------------------------------- // code starts here

    var rows = count('my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content/my:Material_Description_2'); // fetch number of rows in repeating table.
     
    for (var i = 0; i < rows; i++) {
        var materialDescription = $form.getValue('/my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content['+i+']/my:Material_Description_2').toString();
     
        if (materialDescription.match(/Subst/) !== null) {
            $form.setValue('/my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content['+i+']/my:Checking_Group_for_Availability_Check', "CH");
        } else {
            $form.setValue('/my:myFields/my:Sales_Purchasing_data/my:Input/my:Repeating_Content['+i+']/my:Checking_Group_for_Availability_Check', "YS");
        }
    }
    ------------------------------- //code ends here
    Hope this helps.
    Regards


    ------------------------------
    Hammad Naeem
    Precisely Software Inc.
    ------------------------------



  • 9.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Employee
    Posted 30 days ago
      |   view attached

    Hi @Mirka Ploemen

    IDK what version of Evolve you're using, but I just tried a couple of things with a simple test solution in Evolve 20.3.1. 

    If I put the rule on Description in the "target" table with the avail check, and set the rule to run onload, it works

    I use an Excel upload to populate source table (don't want to type)

    use button to copy values to source table

    Rule sets AvailCheck based on ProductDescription2 rules.

    I am attaching my simple test solution.  I had to zip it up, as this platform doesn't like the .wzip file type.

    FWIW,

    Sigrid



    ------------------------------
    Sigrid Kok
    Precisely Software Inc.
    ------------------------------

    Attachment(s)



  • 10.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Posted 18 days ago

    Hallo Sigrid, 

    many thanks for your help; the 'run on load' did it. 

    It works now perfectly fine.

    Regards, 

    Mirka



    ------------------------------
    Mirka Ploemen
    Process Controller
    Smurfit Kappa Group plc
    Roermond
    ------------------------------



  • 11.  RE: How to set a field value in a repeating Table based on the entry of another field per row

    Employee
    Posted 18 days ago

    Yay - really like a simple fix, if at all possible, but I do know JavaScript does give you more control.  Thanks for letting us know, Mirka!

    Best Regards,

    Sigrid



    ------------------------------
    Sigrid Kok
    Precisely Software Inc.
    ------------------------------