Encounter Business Rule Script Processing Issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 08:08 PM
Hello,
I'm currently learning about Business Rule Scripts, but I've encountered an issue. While the business rule runs on sc_req_item table without errors, it fails to correctly populate the 'requested for' name in the 'sc_task'.
Can someone please help review the code and let me know where I did incorrectly. Thank you
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request_item = current.sys_id;
var senderName = getUserByEmail('abraham.lincoln@example.com');
if (senderName) {
gr.request_item.requested_for = senderName;
gr.description = "Requester: " + senderName;
} else {
return null;
//gs.info("Unable to find user for email: abraham.lincoln@example.com");
}
gr.insert();
})(current, previous);
// Function to get name from sys_user table based on email
function getUserByEmail(userEmail) {
var userGR = new GlideRecord('sys_user');
if (userGR.get('email', userEmail)) {
// return userGR.name.toString();
return userGR.getUniqueValue();
} else {
return null;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 01:27 PM
Hi,
1/ before adding the field to the form you will need to add\create the new field on your table.
Then add the field to the form - it may be added to the form by the platform during creation, but unlikely to be positioned where you want it.
2/ Once you have added the field to the form you can show\hide the field using UI policy (preferred option) or an onLoad client script.
3/ No customizations are not overwritten by upgrade, but you will find skipped upgrade records relating to form/list layouts and any customized OOB scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 10:05 PM
Hi @Meera_P ,
Ideally different requesters should have different RITMs under single request. If you look at the dictionary info of "Requested for" on "sc_task" table , is requested_for of the related "sc_req_item" record.
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Kavita Bhojane
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 09:40 PM
Hi @Meera_P ,
Thank you for acknowledging my response as helpful.
If my assistance proved beneficial, please mark it as correct and close the thread to benefit future readers.
Regards,
Kavita Bhojane
