i am updating task in some stage, but it's updating another task also

Gillerla Rajesh
Tera Contributor

i am updating task1  in some stage, but it's updating all the task's, this is the script i have done. 

i need to update only task1 only remain don't need to update

 

after -Business Rule

condition- state - changes to- pending for dispatch

 

var task = new GlideRecord('wm_task');
    task.addQuery('sys_id', current.sys_id);
    task.addQuery('parent.u_rpm','Addition');
    task.orderBy('sys_created_on');
    task.setLimit(1);
    task.query();
    if (task.next()) {
        task.u_hold_the_task = 'yes';
        task.update();
    }
 
any one help me what mistake i have done
2 REPLIES 2

Uncle Rob
Kilo Patron

Could you show us the conditions?   Its possible that this script is doing fine just updating ONE thing, but there's subsequent updates being handled some other place.  You could do a lot of discovery on this by leveraging log statements.  This video might help.
https://youtu.be/hleufTixf6E

Second thing, why is this happening AFTER, then you're updating the record?
If you used BEFORE, you could make the alteration to u_hold_the_task without having to process a second transaction on the task.

 

Mark Manders
Mega Patron

Can you elaborate on what you are trying to do? Is this a child task that needs to update when a parent state changes?

 

Your script looks weird, because you are querying to another table (you say it's a BR, so it runs on 'current') and within your BR you are querying to the wm_task table where the sys_id of the record is the current sys_id. So you are querying to your current record through the wm_task table. 

 

As I don't know your instance, it will be hard to give you the correct logic to put into your script, but I would start looking at what I wrote above.

For triggering the other records: check on any BR's/Flows that do something with mutations on your task. You could always use 'setWorkflow(false)' to ensure you aren't triggering any other updates.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark