- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2017 08:21 AM
Hi All,
I was asked to make a pretty simple business rule but it turns out I need to script in order to get it to work.
Could anyone help me with the following? (Don't worry, we just hired a resource and I will be sharing this as an example so we can write our own soon)
I have added a field to our LOCATIONS table (cmn_location) called "Stock Control". It's a reference field to users. The plan is to use the field to assign hardware requests when the Assignment group is changed to "Stock Control".
Here's the pseudo script on the REQUEST TABLE.
Before
Insert/Update
IF 'Assignment Group' changes to "ITSM - StockRoom", Set the "Assigned to" to Same as 'location.u_stock_control_ref'
Please help if you can.
Thank you,
Carl
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2017 09:16 AM
Hello Carl,
Create the Before business rule with filter condition i.e assignment group | changes to | ITSM - StockRoom with scripts as
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.assigned_to = current.location.u_stock_control_ref;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2017 09:10 AM
Hi Carl,
I think I understand what you are asking for - Here's how I would go about it.
Create your business rule with advanced box ticked. In the "When to run" tab choose when assignment group changes.
Then in your Advanced tab, put a script condition to only run the script when the assignment group is now "ITSM - StockRoom"
The script will find the current location (which i'm guessing is a reference field) in the 'cmn_location' table & then set your 'assigned to' to be the user stored in your new field on the location record.
Here the code for copy & pasting purposes!
Condition:
(current.assignment_group == "ITSM - StockRoom")
Script:
var gr = new GlideRecord('cmn_location');
gr.addQuery('sys_id', current.location);
gr.query();
if(gr.next()) {
current.assigned_to = gr.u_stock_control_ref;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2017 09:16 AM
Hello Carl,
Create the Before business rule with filter condition i.e assignment group | changes to | ITSM - StockRoom with scripts as
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.assigned_to = current.location.u_stock_control_ref;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2017 09:20 AM
Ah yes, you could just dot walk to it instead of creating a glide record!
Do this!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2017 10:25 AM