- 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 05:18 PM
Thank you!
I tried adding that in — and the RITM gets created — but those 2x fields populate with default info - not what I specified.
Looking in error logs — I can see a java error — "java.lang.IllegalArgumentException: Group undefined does not exist.: java.lang.RuntimeException: java.lang.IllegalArgumentException: Group undefined does not exist.:"
Strange since everything else worked, I copied and pasted your code- and also copied and pasted team name / requestor (rather than typing it in).
I wonder if it could be something specific to our environment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 05:21 PM
Actually I commented that segment of code out (requestor and group) and created some more RITMs and still get error - so I think the error is unrelated to that code chunk.
Frustrating!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 05:27 PM
Hi Cath,
This is a bug that was fixed - as far as I remember - in Istanbul patch 6. I had HI ticket opened about this error and that's what I was told. Didn't have a chance to test it yet though.
Regards
Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 05:35 PM
Thank you!
Filtering out irrelevant errors helps (especially when Im so new to scripting / reading error logs like this)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 06:01 PM
Hi Cath,
I see your code has something wrong there var gr = new GlideRecord('sc_req)item'); table name should be sc_req_item
(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.setDisplayValue('Fred Smith'); //hoping field is referenced to sys_user
gr.assignment_group.setDisplayValue('Network');
//gr.u_requestor = 'Fred Smith'
//gr.assignment_group = 'Test Group'
gr.insert();
})(current, previous);
if you go below in system logs arrow will point be pointed (like ==>) where it's wrong in code,