Auto-populate the assigned to field within the Hardware New record with a business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi,
I am trying to auto-populate the 'Assigned to' field in the Hardware New record with the user from the 'Requested for' field in the Requested Item, after the RITM number is populated in a custom field called 'RITM Number' in the Hardware New record.
I tried to auto-populate the 'Assigned to' field with a business rule I created, but whenever I add an RITM number to my custom field in the Hardware New record, the 'Assigned to' field remains empty.
My steps:
1. Accessed the business rules under system definition.
Created a business rule new record:
1. Advanced = checked
When to run:
1. When = before.
2. Update = checked.
Advanced:
1. I created a custom script.
See Assigned to1 and Assigned to2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @BenFan,
Issue with your business rule is you're handling condition wrongly, 'number' is treated as a string, not a field. This condition will almost always evaluate to false, conditions should not compare fields to literal strings like this. Handle the logic inside the script, not in the condition field.
Try this script please:
(function executeRule(current, previous) {
// Only proceed if number is not empty
if (!current.number)
return;
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('number', current.number);
ritmGr.query();
if (ritmGr.next()) {
// Populate Assigned To from Requested For
current.assigned_to = ritmGr.requested_for;
}
})(current, previous);If you find my response helpful, mark it as helpful and accepted solution.
Regards,
Maham Tahir.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I am using a nearly identical script. The only difference is that I don't have the line that says to proceed only if the field is filled out. Would the if (!current.number) syntax be the reason why the business rule isn't working?
I am reattaching the images. Let me know if you can see them.
current.assigned_to.nil() && current.u_ritm_number=='number'
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('number', current.u_ritm_number);
ritmGr.query();
if (ritmGr.next()) {
current.assigned_to = ritmGr.requested_for;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
I can't view your attachments, but what table is the Business Rule running on? Is your custom field a reference to the sc_req_item table? It should be, so that all you need to do is something like:
current.assigned_to = u_ritm.requested_for;
Also note that since you are only running this before Update, the record must already exist before the update will happen, and you should probably add RITM changes to the Filter Conditions so that it doesn't run with every update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
The table I am targeting is alm_hardware.
Yes, my custom field references sc_req_item, just like the 'requested for' field on RITM.
Condition
current.assigned_to.nil() && current.u_ritm_number=='number'(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('number', current.u_ritm_number);
ritmGr.query();
if (ritmGr.next()) {
current.assigned_to = ritmGr.requested_for;
}
})(current, previous);