- 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 06:30 PM
Thank you - sorry that was atypo on my part.
I recreated in my dev instance so I could show issue - and have same issue.
Eg - code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('sc_req_item');
gr.assignment_group.setDisplayValue('Hardware');
gr.comments = 'New Computer Created - Action required';
gr.short_description = 'New Computer Created - Action required';
gr.description = 'Computer SNID: ' + current.serial_number + 'Speak to user and find out what software to deploy';
gr.insert();
})(current, previous);
Creates a RITM (correct) - but the assignment group is not set (I used one of the groups available in the developer instance) - and no errors that seem relevant in logs?
Thank you for all your help - understand if this is asking for too much support now!
Cath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 06:38 PM
Hi Cath,
Have you tried assigning sys_id directly?
gr.assignment_group = "sys_id_of_the_group";
Do you still have an issue then?
Regards
Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 07:31 PM
Thank you!
It works ... on some fields but not others ..... weird?
Eg below (this is all out of generic developer instance - so I think sys_ids should be consistent for anyone replicating in their developer instances?)
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('sc_req_item');
gr.assignment_group = '287ebd7da9fe198100f92cc8d1d2154e'; //sys_id of network team
gr.requested_for = '62826bf03710200044e0bfc8bcbe5de'; //sys_id of a user
gr.comments = 'New Computer Created - Action required';
gr.short_description = 'New Computer Created - Action required';
gr.configuration_item = 'a8adeb280f13320030ac48dce1050e97'; //sys ID of a PC to use always
gr.description = 'Computer SNID: ' + current.serial_number + ' Speak to user and find out what software to deploy';
gr.insert();
})(current, previous);
Assignment group, and config item work, yet requested for does not......

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 07:59 PM
Hi Cath,
Can you please try with below code:
gr.setValue('requested_for','62826bf03710200044e0bfc8bcbe5de');
Please try with setValue() wherever you are passing sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 10:35 AM
Hi Cath,
I think the issue with Request for is that this field is not on sc_req_item table. It's brought from sc_request table. So you would have to first create a request and then populate that field there and you will see it on sc_req_item record.
Regards
Greg