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.
------------------------------
Original Message:
Sent: 03-20-2024 12:39
From: Hammad Naeem
Subject: How to set a field value in a repeating Table based on the entry of another field per row
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.
Original Message:
Sent: 03-20-2024 11:54
From: Mirka Ploemen
Subject: How to set a field value in a repeating Table based on the entry of another field per row
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
Original Message:
Sent: 03-20-2024 09:40
From: Mirka Ploemen
Subject: How to set a field value in a repeating Table based on the entry of another field per row
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
Original Message:
Sent: 03-18-2024 16:51
From: Sigrid Kok
Subject: How to set a field value in a repeating Table based on the entry of another field per row
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.
Original Message:
Sent: 03-18-2024 11:14
From: Mirka Ploemen
Subject: How to set a field value in a repeating Table based on the entry of another field per row
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
------------------------------