- 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-08-2017 12:30 AM
Thank you so much Shishir (and everyone else also).
I went with Shishir's approach (screenshots and example scripts help because I'm very basic at scripting right now).
I used the example script, then have been just tweaking fields to add and remove - but working a charm.
Thank you so much!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 12:35 AM
Thank you Cath for your feedback, Can you please mark my answer correct if I was able to help you.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review https://community.servicenow.com/docs/DOC-5601
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 04:46 PM
A follow up question:
With your code:
--------------------
(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);
----------------------------
I have modified it to create a request item instead.
When I do: " gr.short_description = 'New Incident on addition of new Record in Service Request Table';" as part of code chunk it works, however when I try and set a requestor, or assignment group - this doesn't seem to do anything? EG:
----------------------------
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('sc_req)item');
gr.comments = 'Test new RITM';
gr.short_description = 'Test RITM based on criteria 123';
gr.u_requestor = 'Fred Smith'
gr.assignment_group = 'Test Group'
gr.insert();
})(current, previous);
----------------------------
I have tried variations such as:
gr.assignment_group = (group sys_id)
gr.assignment_group.name = 'Group Display Name'
What am I missing here?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 05:00 PM
Hi Cath,
I believe, you should be able to do with below code. Please try if it works, I will test mean while on my instance.
gr.assignment_group.setDisplayValue('The value you want to enter');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 05:10 PM
Hi Cath,
I have just verified and it worked for me, please try below code as per your need. Hope this helps.
gr.u_requestor.setDisplayValue('Name of the requester');
gr.assignment_group.setDisplayValue('name of the group');