onChange like business rule to trigger on change of variable on sc_task form,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 09:45 PM
Hi Experts,
I've a requirement where i need to trigger a integration based on variable value change on sc_task form.
I'm hosting some catalog variables on sc_task table, when the fulfiller changes the value on it , it will trigger different type of response.
i'm using the after - update business rule, I'm not able to get the previous value to match the on change field, thus i'm not able to do the correct comparison on changed values.
Here is the code , i've tried fetching values from sc_req_item table as well, same result, kindly let me known if you've any insight's on it.
(function executeRule(current, previous /*null when async*/ ) {
var currentVariable1 = current.variables.variable1.getValue();
var previousVariable1 = previous.variables.variable1.getValue(); // this returns empty or same as current value
var currentVariable2 = current.variables.variable2.getValue();
var previousVariable2 = previous.variables.variable2.getValue();
gs.log("test123 :" + currentVariable1 + " previous " + previousVariable1 + " Current variable2 " + currentVariable2 + " previous variable2 " + previousVariable2);
if ((currentVariable1 != previousVariable1) || (currentVariable2 != previousVariable2)) {
current.setWorkflow(false);
gs.log("test123 :4" + currentVariable1 + " previous " + previousVariable1 + " Current variable2 " + currentVariable2 + " previous variable2 " + previousVariable2); // this log never triggers
gs.eventQueue('abc', current, 'xyz');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 10:04 PM
Hi @Varun Sharma
When using the 'previous' object in the "after" Business Rule to fetch the previous value of 'variables', the Business Rule will not fetch the correct previous value. This only happens with the "after" Business Rule.
Try with Before Update Br
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1278663#:~:text=When%20using%....
Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution
Thanks
Eshwar