- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 02:37 AM
Hi all,
I was looking a script in business rule to update a field on the form based on the multiple conditions like below:
-> Field "Country" contains value as "India" then update a field "User" with multiple field values (/FieldA/FieldB/FieldC/)
-> Here combinational query If "Country" does not contains value "India" and field "City" has a value "Pune", then update "User2" field with (/FieldD/FieldE/FieldF/)
2 more conditions are included as above (combination).
Could you please help me on it? How to consider contains in BR in if condition.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 02:51 AM
Hi @Ksnow ,
I trust you are doing great.
please find the below reference code
(function executeRule(current, previous /*null when async*/) {
// Check if Country contains 'India'
if (current.country.indexOf('India') > -1) {
// Update User field with concatenated values
current.user = current.fieldA + '/' + current.fieldB + '/' + current.fieldC;
}
// Check if Country does not contain 'India' and City is 'Pune'
else if (current.country.indexOf('India') == -1 && current.city == 'Pune') {
// Update User2 field with concatenated values
current.user2 = current.fieldD + '/' + current.fieldE + '/' + current.fieldF;
}
// Add additional conditions here following the same pattern
// Commit the changes
current.update();
})(current, previous);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 02:51 AM
Hi @Ksnow ,
I trust you are doing great.
please find the below reference code
(function executeRule(current, previous /*null when async*/) {
// Check if Country contains 'India'
if (current.country.indexOf('India') > -1) {
// Update User field with concatenated values
current.user = current.fieldA + '/' + current.fieldB + '/' + current.fieldC;
}
// Check if Country does not contain 'India' and City is 'Pune'
else if (current.country.indexOf('India') == -1 && current.city == 'Pune') {
// Update User2 field with concatenated values
current.user2 = current.fieldD + '/' + current.fieldE + '/' + current.fieldF;
}
// Add additional conditions here following the same pattern
// Commit the changes
current.update();
})(current, previous);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 02:58 AM - edited 11-15-2023 02:59 AM
Thank you very much for prompt response.
Can I run it on "before"?
Appreciate your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 02:59 AM
Yes
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 03:31 AM
Thanks @Amit Gujarathi
But It's working exactly opposite, seems strange.
Country field (reference) has 4 records, in which 2 records contains "India" and another 2 doesn't contain.
When contain "India" selected, user2 is being updated and India doesn't contain updating User1
Thanks again!