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.

Create Change UI Action query

Cirrus
Kilo Sage

Hi,

We would like to create a change from a catalog task, and can achieve this simply by using the following script in a ui action:

var url = new GlideURL("change_request.do");
url.set("sys_id" , "-1");
url.set("sysparm_query" , "^parent=" + current.sys_id);
action.setRedirectURL(url.toString()+"");
 
is there a way to amend the script to set other fields, for example the Short Description, from the parent catalog task??
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Yes, you need to add it on one set(). Like this:

var url = new GlideURL("change_request.do");
url.set("sys_id" , "-1");
//url.set("sysparm_query" , "^parent=" + current.sys_id);
url.set("sysparm_query" , "^short_description=" + current.short_description +^parent=" + current.sys_id);

action.setRedirectURL(url.toString()+"");

View solution in original post

10 REPLIES 10

Hi Cirrus,

You're mixing and matching how you assign values to your gliderecord which is why it's not working.

change.parent = current.number; isn't correct, you need to assign the sys_id, not the number.

 

//ChangeRequest is an OOB Script Include that provides APIs
//for creating changes in conformity to the different change models available
var changeRequest = ChangeRequest.newNormal();

changeRequest.setValue("short_description", current.getValue('short_description'));
changeRequest.setValue("description", current.getValue('u_details'));
changeRequest.setValue("cmdb_ci", current.getValue('u_service'));
if (changeRequest.hasValidChoice('priority', current.getValue('priority')))
    changeRequest.setValue("priority", current.getValue('priority'));
changeRequest.setValue("requested_by", current.getValue('caller_id'));

action.setReturnURL(current); //We're not inserted the gliderecord yet, so this prevents accidental UI action clicks causing record creation
action.openGlideRecord(changeRequest.getGlideRecord())

Community Alums
Not applicable

Yes, you can prepopulate your new change using the URL parameters. Just follow this syntax:

sysparm_query=<field to be prepopulated>=<values> and it will be easier to achieve what you need as you already have it working on 80%

Community Alums
Not applicable

You can try with adding more fields in the sysparm_query parameter passed to the URL. Add ^ for every extra field. I just tested it to be sure its still working that way and using /incident.do%3Fsys_id%3D-1%26sysparm_query%3Ddescription%3DMYDESCRIPTION%5Eshort_description%3DSHORTDESC was working just fine.

 

url.set("sysparm_query" , "^parent=" + current.sys_id + "^description=" + current.description);

 

Sorry, I replied before seeing this. That does exactly what we need it to do. Thankyou

 

Thanks Joro, are you able to exemplify please. If I insert in line 4 it does populate the short description, but it stops populating the Parent with the sc_task number

 

var url = new GlideURL("change_request.do");
url.set("sys_id" , "-1");
url.set("sysparm_query" , "^parent=" + current.sys_id);

url.set("sysparm_query" , "^short_description=" + current.short_description);

action.setRedirectURL(url.toString()+"");