Create Request from Incident Business Rule

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2018 12:00 PM
Having an issue creating a request from an incident through a Business Rule. I'm able to get the request and request item created, but I'm not able to copy any variables from the Incident to the Request Item.
I would like to create a relationship between them or at least have the incident show in the 'Parent' field for reference. Once that is accomplished I might want to copy over other fields as well.
I'm creating the request with an after business rule and the following code:
createRequest();
function createRequest(current,previous)
{
var cart = new Cart();
var item = cart.addItem('fa593675db682380183464904b96198a');
var rc = cart.placeOrder();
gs.addInfoMessage('New/Update Configuration Item Request Created');
}
The business rule is triggered by a specific field being selected on the form. The business rule is triggering off the Task table since I'm going to want this to also apply to problems and changes.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2018 12:27 PM
Hi David, If I understand your question correctly, you having issue copying certain incident variables to new 'request' that you are creating through business rule,
if that's the case, to copy any variables on INC form to new request use this in your function createRequest() as many as you want.
cart.setVariable('cat_item_name', 'cat_variable_name', current.XYZ); //
var rc = cart.placeOrder();
and to add Incident reference on new request, do glide record on above request using rc.sys_id and setvalue for parent with current.getUniquevalue();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2018 12:34 PM
Nari:
You are understanding me correctly. Scripting is not my strong-suit. Would you be able to provide an example based on the code i provided?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2018 09:04 PM
Hi David, it is just adding one more lines b/w your code. I took an example below, to copy incident short_description, category and caller_id to request item, let me know if this doesn't work.
createRequest();
function createRequest(current,previous)
{
var cart = new Cart();
var item = cart.addItem('fa593675db682380183464904b96198a');
cart.setVariable(item, 'your_catalog_variable_name_1', current.short_description);
cart.setVariable(item, 'your_catalog_variable_name_2', current.caller_id);
cart.setVariable(item, 'your_catalog_variable_name_3', current.category);
var rc = cart.placeOrder();
gs.addInfoMessage('New/Update '+ rc.number + ' Configuration Item Request Created');
}
to refer incident as parent in this newly created request do this
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", rc.sys_id);
gr.query();
if (gr.next()) {
gr.setValue('parent', current.getUniqueValue())
gr.update();
}
just thought of sharing scripting in ServiceNow is so simple as you start doing it, refer to docs you get everything from their.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2018 04:20 PM
Did you able to get it worked