Populate catalog task opened_by to be the same user who opened the request_item

Anna Gausel
Giga Expert

We have custom workflow framework to simplify our workflows and as a result all of our catalog task default the opened_by to 'system'

I've written an after insert/update business rule, but it is not updating the opened_by:

var sctask = new GlideRecord('sc_task');
sctask.get(current.sc_task);
sctask.opened_by = current.request_item.opened_by;
sctask.update();

I've reversed the logic and got it working the other way around:

var sctask = new GlideRecord('sc_req_item');
sctask.get(current.request_item);
sctask.opened_by = current.opened_by; //populates the RITM opened_by to 'system'
sctask.update();

Any ideas why my first script does not update the opened_by?

1 ACCEPTED SOLUTION

Anna Gausel
Giga Expert

Got it working correctly on the sc_task table:

current.opened_by = current.request_item.opened_by

I had my business running on after insert/update instead of before.

View solution in original post

12 REPLIES 12

Can you check if there is an ACL write that is stopping the update on sc_task

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

The only write ACL we have on sc_task is the one to allow itil users write access, so it doesn't appear to be an ACL affecting it.

Can we try this??

var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item',current.request_item);
sctask.query();
while(sctask.next()){
sctask.opened_by = current.request_item.opened_by;
sctask.update();
}

Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Just to be sure are you getting the right sys_ids

Please double check.

 

var sctask = new GlideRecord('sc_task');
sctask.get('sys_id of sc_task');
sctask.opened_by = 'sys_id of requested item opened by';
var updated = sctask.update();
gs.info('updated sysid = ' + updated);

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Thanks, yes - the sys_id of the requested item opened by appears in the log statements, but it doesn't update in the related tasks