In After Business Rule, current record holding old values for most of the variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 04:12 AM
I have a custom table and I created a Business Rule on a filed with the following details:
When: After - Update
Field changes to "In Progress"
And the requirement is to trigger a workflow. In advanced I have the following lines:
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('workflow name'), current, 'update');
Other than the filed specified in the filter condition (trigger condition), every other columns of the "current" and "previous" are same. (I printed all the table columns in the log using the current and previous objects).
I want to pass the updated record (during the update of the record couple of other fields also get updated other than the trigger field) and I am updated one column a(as trigger column) to ex: sync required to "In Progress" to trigger the same workflow for update to the table record.
Why the business rule is holding a record with only trigger field with new value and remaining fields with old values. I need to use the new values in the workflow.
Thanks in advance for your inputs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 05:12 AM
Hi @Suneel9 ,
You need to execute the update command before calling flow.
current.update(); // Save the record with the updated values
// Trigger workflow after the record is saved
var wflw = new Workflow();
var workflowID = wflw.getWorkflowFromName('workflow name');
// Start the workflow on the updated record
wflw.startFlow(workflowID, current, 'update');
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 05:20 AM - edited 01-28-2025 06:54 PM
what's your Business requirement here?
try to force the update and then trigger the workflow
(function executeRule(current, previous /*null when async*/) {
// Check if the field has changed to "In Progress"
if (current.field_name == 'In Progress' && previous.field_name != 'In Progress') {
// Update the record to ensure all changes are saved
current.update();
// Start the workflow
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('workflow name'), current, 'update');
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 06:55 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 04:02 AM
Thank you for the response @Ankur Bawiskar @Runjay Patel.
The issue was I was using "After" + "Update" when condition and both current and previous holding the same data. After I changed my when condition to "Before" + "Update", I see the correct values in current & previous.
Also for some reason in my filter condition Field Name "Changes to" "In Progress" also causing some problem. I modified it to use Field Name "is" In Progress.
Once I have some free time in next couple of weeks I will check the suggestion provided and update the thread.