UI action - create requested item from an incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2015 02:24 PM
Hi SNC,
I want to create a RITM from an incident, using an UI action. Below is my code, my questions are in red:
createRITM();
// update the record once, after the function call
current.active = false;
current.state = 9; //setting it to closed state
current.updateWithReferences();
function createRITM() { //create the new Requested Item Record
var newReq = new GlideRecord("sc_req_item");
newReq.initialize();
newReq.opened_by=current.opened_by;
newReq.assignment_group='4e868fe1508381002cf0066911d9982c';
newReq.cmdb_ci=current.cmdb_ci;
newReq.u_business_service=current.u_business_service;
newReq.u_customer_defined_urgency=current.u_customer_defined_urgency;
newReq.variables=current.variables; //I am storing catalog item variables in a formatter, called Requested Item Variable Editor, and I wanted to transfer the variables from the incident into the RITM, but it does not happen
newReq.description=current.description;
newReq.short_description=current.short_description;
newReq.contact_type='2';
newReq.state=current.state;
newReq.priority=current.priority;
newReq.watch_list=current.watch_list.getDisplayValue().toString();
newReq.parent=current.number; //I can't get this working - cannot populate the Parent field in the RITM with the ID of the incident
newReq.insert();
// now direct to the new Request
gs.addInfoMessage("Incident closed, Requested Item " + newReq.number + " created.");
action.setRedirectURL(newReq);
action.setReturnURL(current);
}
Would you throw a sanity check eye on this?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2015 03:20 PM
newReq.parent=current.sys_id; worked for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2015 03:58 PM
Hi Dimitar,
Here goes some inputs to your questions:
1) newReq.variables=current.variables; //I am storing catalog item variables in a formatter, called Requested Item Variable Editor, and I wanted to transfer the variables from the incident into the RITM, but it does not happen
I don't think that assignment works that way, and if it does most probably you're copying the "pointer" to the current variables, which most probably it's not what you're expecting. I will rather recommend copying all the variables one by one.
newReq.parent=current.number; //I can't get this working - cannot populate the Parent field in the RITM with the ID of the incident
Change it to newReq.parent = current;
You could also write it like Mike suggested previously, but according to a ServiceNow Coding Best practice dot-walking to a record's sys_id is not recommended since it adds an additional database query that could have been avoided. Coding Best Practices - ServiceNow Wiki
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2015 04:03 PM
As for how to copy the variables from your current RITM into a new RITM, you can find the code in the following thread:
Copying variables field from Requested Item to a new record
I hope this is helpful! Please let us know if you have any further questions.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2015 02:32 PM
Berny Alvarado How do you think the code would look like for my conversion RITM-INC, and INC-RITM? I still can't figure it out right.