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

Just tested this:

find_real_file.png

find_real_file.png

 

Worked like a charm!

Thank you, patricklatella, for continuing this conversation which led to my understanding to get this working.

 

Docs references:

 

Ok, I promise, last post by me...  for sc_task creation in a workflow, all you need is setNewGuid() as clearly indicated in the developer docs:

 

find_real_file.png

excellent!

Hello Patrick,

setNewGuid(); only works in the global app scope. Do you know how I can leverage the same exact functionality of this function on scoped apps? 

Note: I am aware of setNewGuidValue(sysId), I do not want to pass in a sysid - i want the system generated one within the catalog task workflow activity. 

 

Any ideas? thank you 🙂 

can you explain a little more about the requirement for the task's sys_id?