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

harun_isakovic
Mega Guru

To access the variables you do like this

<recordObject>.variables.<variableName>
//So it would look something like this if you queried a RITM record
ritm.variables.software_id
//Or if you are trying to access variables from the current record object
current.variables.software_id

Getting variable values from current.variables.variableName I know and understand.

What I am not sure about is how to write the code in the supplied script above to copy the ritm variable values over to the INC record being created.

If you want to create a new Incident from RITM using a UI Action, I suggest something like the following. Note that the script works in 2 steps. The first is to create the Incident record object and map the values. The second is to redirect the user to the new Incident record.

 

// 1. Create new Incident
var incGr = new GlideRecord('incident');
incGr.newRecord();
if(current.requested_for) {
  incGr.caller_id = current.requested_for; // Set Incident.Caller to RITM.Requested for
}
else {
  incGr.caller_id = current.request.requested_for; // Set Incident.Caller to RITM.Request.Requested for
}
incGr.parent = current.getUniqueValue(); // Set Incident.Parent to RITM record
incGr.short_description = current.variables.short_description; // Set Incident.Short Description to RITM Variable called short_description
// (add more field mappings here)
incGr.insert();

// 2. Redirect user to new Incident
action.setRedirectURL(incGr);

Jake Gillespie
Mega Guru

As posted above, you can access the variable values by using the .variables property on the RITM GlideRecord Object. If the variable is a Reference or Choice type you can also use .getDisplayValue() to return the display value instead of the stored value.

 

Note that RITM variables are stored in the Options [sc_item_option] table and linked to the RITM via a M2M table caller Variable Ownership [sc_item_option_mtom] (where Parent Item references the RITM and Dependent Item references the Option/Variable answer). Although the above method using .variables is quick and easy, sometimes you may need to run a GlideRecord query against these records to gather more information, such as the type or order of each variable.