The CreatorCon Call for Content is officially open! Get started here.

In After Business Rule, current record holding old values for most of the variables

Suneel9
Tera Contributor

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.

 

 

5 REPLIES 5

Runjay Patel
Giga Sage

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

-------------------------------------------------------------------------

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Suneel9 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Suneel9 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Suneel9
Tera Contributor

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.