- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:10 AM
I need to map variables of catalog item into sc_req_item fields.
Requested for --> u_requested (reference to sys_user)
Location --> location
sc_category --> u_category_task
Watch list --> watch_list
Technician name --> work_notes_list
Estimated end --> estimated_delivery
Equipment --> cmdb_ci, configuration_item
For this I'm using after insert business rule, but I couldn't achieve it. Here is the BR:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 10:01 AM - edited 09-18-2024 10:04 AM
The Filter Condition should be fine. Reference qualifiers don't matter when setting values via script. I can see that the Request for variable is a reference type, but is the u_requested field also a reference type? This is what has to match on each variable and field - so that you're not trying to populate a string value from a variable in a reference type field, etc. To confirm this script is running and the variable values, these are the types of logs I was recommending, and removing the current.update() when switching the BR to before insert. This will help narrow down if there is a conflict between variable type and field type:
(function executeRule(current, previous /*null when async*/) {
gs.info('BR RITM running ' + current.number);
gs.info('BR variable values ' + current.variables.requested_for + ' | ' + current.variables.location + ' | ' + current.variables.sc_category);
current.u_requested = current.variables.requested_for;
if (current.variables.location) {
current.location = current.variables.location;
}
if (current.variables.sc_category) {
current.u_category_task = current.variables.sc_category;
}
if (current.variables.watch_list) {
current.watch_list = current.variables.watch_list;
}
if (current.variables.technician_name) {
current.work_notes_list = current.variables.technician_name;
}
if (current.variables.estimated_end) {
current.estimated_delivery = current.variables.estimated_end;
}
if (current.variables.equipment) {
current.cmdb_ci = current.variables.equipment;
current.configuration_item = current.variables.equipment;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:15 AM - edited 09-18-2024 09:16 AM
Is this Business Rule running on the sc_req_item table? Do you have any Filter Conditions, or a Condition on the Advanced tab? Do the variable types agree with the field types? Change it to before Insert and remove the current.update() to prevent an unnecessary update. You can further troubleshoot this by adding logs to the script to confirm it is running, and the values of each variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:20 AM
Yes it is running on sc_req_item table , and added filter condition "item is gas detection(catalog item)"
Here is brief about fields
Variables:
Requested for (active = true & user_type = ST)
Location
Sc_Category
Watch list
Estimated end: date/time
Equipment: reference of u_manufacturing_equipment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 10:01 AM - edited 09-18-2024 10:04 AM
The Filter Condition should be fine. Reference qualifiers don't matter when setting values via script. I can see that the Request for variable is a reference type, but is the u_requested field also a reference type? This is what has to match on each variable and field - so that you're not trying to populate a string value from a variable in a reference type field, etc. To confirm this script is running and the variable values, these are the types of logs I was recommending, and removing the current.update() when switching the BR to before insert. This will help narrow down if there is a conflict between variable type and field type:
(function executeRule(current, previous /*null when async*/) {
gs.info('BR RITM running ' + current.number);
gs.info('BR variable values ' + current.variables.requested_for + ' | ' + current.variables.location + ' | ' + current.variables.sc_category);
current.u_requested = current.variables.requested_for;
if (current.variables.location) {
current.location = current.variables.location;
}
if (current.variables.sc_category) {
current.u_category_task = current.variables.sc_category;
}
if (current.variables.watch_list) {
current.watch_list = current.variables.watch_list;
}
if (current.variables.technician_name) {
current.work_notes_list = current.variables.technician_name;
}
if (current.variables.estimated_end) {
current.estimated_delivery = current.variables.estimated_end;
}
if (current.variables.equipment) {
current.cmdb_ci = current.variables.equipment;
current.configuration_item = current.variables.equipment;
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:34 AM
Hi @Pushpanjali3 ,
Instead of using after BR please use Before BR, because it is not recommendable to use current.update() in after BR. Please make it Before and in before you don't want to update that, So please check below script
(function executeRule(current, previous /*null when async*/ ) {
// Check if the current RITM is being created or updated
//if (current.variables.requested_for) {
current.u_requested = current.variables.requested_for;
// }
if (current.variables.location) {
current.location = current.variables.location;
}
if (current.variables.sc_category) {
current.u_category_task = current.variables.sc_category;
}
if (current.variables.watch_list) {
current.watch_list = current.variables.watch_list;
}
if (current.variables.technician_name) {
current.work_notes_list = current.variables.technician_name;
}
if (current.variables.estimated_end) {
current.estimated_delivery = current.variables.estimated_end;
}
if (current.variables.equipment) {
current.cmdb_ci = current.variables.equipment;
current.configuration_item = current.variables.equipment;
}
})(current, previous);
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak