Get sys_id of workflow catalog task

xiaix
Tera Guru

I need to edit a field on a newly created catalog task, as soon as it's created.  Normally, I would just do task.field = , but the field I need to update doesn't actually sit on the sc_task table, it sits on the sc_request table and I know you can't do the following:

task.request.requested_for = "foobar";
task.request.update();

I read this post: https://community.servicenow.com/community?id=community_question&sys_id=80570369db1cdbc01dcaf3231f96...

but I'm not sure.

 

So, I did get it to work, but there must be a better way.

 

Here's a diagrammed way I have it now:

find_real_file.png

 

 

find_real_file.png

1 ACCEPTED SOLUTION

patricklatella
Mega Sage

I was actually able to capture the sys_id of the created task (created by the Catalog Task workflow activity) directly in the advanced script section using

workflow.scratchpad.taskid = task.setNewGuid();

View solution in original post

15 REPLIES 15

larstange
Mega Sage

Hi

 

In the task activity you can just add a script to update the request:

 

var req = new GlideRecord('sc_request');

req.get(current.request);

 

req.requested_for = "foobar";

req.update();

Worked perfectly.

 

find_real_file.png

patricklatella
Mega Sage

Hi guys,

I'm trying to do a similar thing, where I'm creating a task with a Catalog Task activity in workflow, then later in the workflow I want to change a field on that task.  I'm trying so grab the sys_id of the task that's created, and then use that in my later activity to query the sc_task table and update via GlideRecord.   However in my Catalog Task activity which is creating the actual task in the first place, I'm having trouble writing the sys_id of the task to the scratchpad.  

I'm trying 

workflow.scratchpad.task_sys_id=task.sys_id;

in the script of the Catalog Task activity, but I'm checking by writing to the system log, and it's not working.  Should this work?

I too needed that sc_task sys_id and ended up using the wait method.  That's the only way I could capture it.

 

find_real_file.png

 

find_real_file.png