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.

fetch the current workflow for a change request

Rex Shi
Giga Contributor

Hi there,

I am trying to write a simple script within the workflow to fetch the current change id within the normal change workflow, i found out its not really working.

var gr = new GlideRecord("change_request");
gr.addQuery('number',current.sys_id);
gr.query();

i think the gr.addQuery('number',current.sys_id) is not working, but i cant find the right value to fetch , has anyone done this before ? 

 

thanks 

1 ACCEPTED SOLUTION

You don't need to query the change record for that. Because you have all the attributes in the current object already. current.number will give you Change ID. current.sys_id will give you sysid of the change request

 

You can use current.assignment_group to get the sys id of the assignment group.

And current.assignment_group.getDisplayValue to get the display value of the assignment group.


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

13 REPLIES 13

You will have to identify which table you are referencing.

For ex, If you have a reference field assignment group referncing sys_group table, you can access all the fields in group table by doing current.assignment_group.<field_name>.

 

For ex, if I want to know the group manager, i can do current.assignment_group.manager.

 

Can you mark my response correct if it worked for you? 


Please mark this response as correct or helpful if it assisted you with your question.

Thanks Sanjiv !

Brent Sutton
Mega Sage

Hi Rex,

Just use current.getUniqueValue() to return the sys_id or current.number if you want the number of the change request.

Thanks,

Brent

P.S. Mark correct if this helped you.

Hi Brent,

 

Thanks for replying, i tried with 

var gr = new GlideRecord("change_request");
gr.addQuery('number','=','current.getValue("number")');
gr.query();

still wont return anything in the workflow.. the workflow that i am using is the approval-User workflow, and i am trying to get this script to look up the assignment_group in the change table, if its the current change has the right assignment group then push that group to Approvers list on the change

Hi Rex,

You don't need to do a GlideRecord query. The information you need is available in the "current" object.

Just remove your GlideRecord query and use the current object. I've provided some examples below:

var chgNumber = current.number; //chgNumber variable be set with the number of current change request.
var assignmentGroupValue = current.assignment_group; //returns sys_id of the assignment_group field.
var assignmentGroupDisplayValue = current.assignment_group.getDisplayValue(); //returns the displayValue of the assignment group.

Any field on the change request, that the workflow is running on, should be available to you in the "current" object.

Brent