- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 04:43 PM
Hi,
my first question - so please excuse me if I have missed anything obvious.
I would like to create a request item - with some pre-populated fields - based on when a record is added to an unrelated table.
So far I have looked at trying to do it by either events, or business rules - but not having much luck (I'm also very green with scripting).
Does anyone have some pointers of how you would implement this?
Thanks,
Cath
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 06:33 PM
Hi Cath,
You can do through Business Rule, let me explain how through scripting since you are new in scripting. This might help you.
For Example: I am here trying to create an Incident when new Record gets added in Service Request (sc_request) table, checking condition that after new record is inserted and state of the newly inserted record in Open then create incident with some populated values.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('incident');
gr.caller_id = gs.getUserID();
gr.comments = 'New Incident on addition of new Record in Service Request Table';
gr.short_description = 'New Incident on addition of new Record in Service Request Table';
gr.category = "inquiry";
gr.incident_state = IncidentState.NEW;
gr.contact_type = "email";
gr.insert();
})(current, previous);
Result:
Hope this will help you to understand how to achieve, just replace the table name on which when you insert new record incident should be created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 04:51 PM
Hi Cath,
Trigger business on the unrelated table,when ever insert new record and pyou want to create Request use cart api in script
Service Catalog Script API - ServiceNow Wiki
var cartId = GlideGuid.generate(null); var cart = new Cart(cartId); var item = cart.addItem('e2132865c0a8016500108d9cee411699'); var rc = cart.placeOrder(); gs.addInfoMessage(rc.number);
Ordering twelve BlackBerries:
var cartId = GlideGuid.generate(null); var cart = new Cart(cartId); var item = cart.addItem('e2132865c0a8016500108d9cee411699', 12); var rc = cart.placeOrder(); gs.addInfoMessage(rc.number);
Ordering an executive desktop and setting its OS:
var cartId = GlideGuid.generate(null); var cart = new Cart(cartId); var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f'); cart.setVariable(item, 'os', 'Linux Red Hat'); var rc = cart.placeOrder(); gs.addInfoMessage(rc.number);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 04:52 PM
Hi Cath,
Please look into new call functionality which creates either incident, request item based on call type.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 04:56 PM
Hi Cath,
One way to do that is to create a business rule on the incident table, that runs after a record is inserted. Then you could use the GlideRecord API to create records on the Requested Item table.
As you want some fields to be pre-populated, the requested item records could be created from a template.
If this post has helped, please choose 'Like', 'Helpful' or 'Correct'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 06:33 PM
Hi Cath,
You can do through Business Rule, let me explain how through scripting since you are new in scripting. This might help you.
For Example: I am here trying to create an Incident when new Record gets added in Service Request (sc_request) table, checking condition that after new record is inserted and state of the newly inserted record in Open then create incident with some populated values.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('incident');
gr.caller_id = gs.getUserID();
gr.comments = 'New Incident on addition of new Record in Service Request Table';
gr.short_description = 'New Incident on addition of new Record in Service Request Table';
gr.category = "inquiry";
gr.incident_state = IncidentState.NEW;
gr.contact_type = "email";
gr.insert();
})(current, previous);
Result:
Hope this will help you to understand how to achieve, just replace the table name on which when you insert new record incident should be created.