Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to fetch current workflow sys id when creating custom activities?

swethachunduri
Kilo Contributor

Hello,

I am creating a custom activity and would like to fetch the current workflow id in which the user uses the activity from within the activity pack. I tried the following in a run script custom activity under ServiceNow orchestration:

var gr = new GlideRecord('wf_context');

gr.addQuery('id',current.sys_id);

gr.query();

this is throwing me   "current not defined" error.

Any idea how I   can fetch current workflow sys id when creating custom activities?

thank you

Swetha

2 REPLIES 2

Deepa Srivastav
Kilo Sage

Hi Shwetha,



Check section 3.15.3 from the below link if it helps.



Workflow Script - ServiceNow Wiki



Else check below code from thread...Re: Workflow creation



var s = new GlideRecord('wf_workflow');


s.addQuery('name', '<workflow_name>');


s.query();


if (s.next()) {


  var workflowId = '' + s.sys_id;


}




Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy


I would like to fetch the sys id without entering the workflow name details as im trying to generate a generic script that reads the current sys_id details and perform certain actions specific to that id