- 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 04:51 AM
Never mind. it's working fine now.
THanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 03:09 AM
did you try to use filter conditions instead?
You can avoid scripting
Any challenge you faced using filter conditions in BR?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 03:32 AM
How to check multiple conditions using the filter and update the field accordingly?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 03:42 AM
simply dot walk to fields you require and use the operator
did you start on this? please share screenshots.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader