How to Populate Requested Item Variables to INC in UI Action "Create Inciden"

kshaw
Giga Guru

I have a generic Get Help request item (none IT).

There are times I need to convert this to an INC because user submitted wrong form. I found a system UI Action "Create Incident" but it only copies the requestor name. How can I get the variable values from the RITM and pass those to the new INC being created. Only need a couple of variables passed from requested item to inc and the watchlist.

UI Action Script

var url = new GlideURL("incident.do");
url.set("sys_id" , "-1");
if(current.requested_for) {
    url.set("sysparm_query" , "caller_id=" + current.requested_for + "^parent=" + current.sys_id);
}
else {
    url.set("sysparm_query" , "caller_id=" + current.request.requested_for + "^parent=" + current.sys_id);
}

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

1 ACCEPTED SOLUTION

Here is the code that I finalized that did work. I added a lengthy query with the additional variables to be copied into the new INC form.

var url = new GlideURL("incident.do");
url.set("sys_id", "-1");
if (current.requested_for) {
    url.set("sysparm_query", "caller_id=" + current.requested_for + "^parent=" + current.sys_id);
} else
    url.set("sysparm_query", "caller_id=" + current.request.requested_for + "^parent=" + current.sys_id);

url.set("sysparm_query", "short_description=" + current.variables.request_title + "^watch_list=" + current.watch_list + "^description=" + current.variables.details + "^contact_type= Tech");
//gs.log("CREATEINC: variables.request_title="+current.variables.request_title);

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

View solution in original post

6 REPLIES 6

Here is the code that I finalized that did work. I added a lengthy query with the additional variables to be copied into the new INC form.

var url = new GlideURL("incident.do");
url.set("sys_id", "-1");
if (current.requested_for) {
    url.set("sysparm_query", "caller_id=" + current.requested_for + "^parent=" + current.sys_id);
} else
    url.set("sysparm_query", "caller_id=" + current.request.requested_for + "^parent=" + current.sys_id);

url.set("sysparm_query", "short_description=" + current.variables.request_title + "^watch_list=" + current.watch_list + "^description=" + current.variables.details + "^contact_type= Tech");
//gs.log("CREATEINC: variables.request_title="+current.variables.request_title);

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

I'm glad you got your solution working!

For reference, you've opted to leverage ServiceNow's capability to apply field values to a record form via URL parameters. In my experience, this works for simple field values (reference fields/sys_id's, choice fields, true/false fields etc.), but you may find it doesn't work when you're putting large bodies of text into those fields via URL parameters.

I noticed you're mapping "current.variables.details" into the Incident Description field. If the source variable type is multi-line text, it has the potential to contain a large amount of text, and that text may include special characters that would otherwise need escaping. I recommend testing your solution for such inputs to confirm it still works as expected.