- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:21 AM
Hi all,
Our customer needs exact field named requestor department on catalog task and want department of requested for in that field.
I created one custom field referring to department table and was trying to update its value based on requested for.
As we know, that catalog task don't have requested for and that needs to be taken from request table, I have written same logic in my before business rule, but department is not getting populated though.
Info logs are showing undefined
Var gr = new GlideRecord('sc_request');
if(gr.get(current.request))
var depart = gr.requested_for.department;
current.u_requestor_department = depart
This code I have written in before insert update br on catalog task table.
Do I need to write after br for this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:50 AM
hi @BijoyDeb
Since you are trying to update the field based on values from another table, you should use an after Business Rule to ensure the record is saved and available for reading.
(function executeRule(current, previous /*null when async*/) {
// Check if the current record is valid and has a request reference
if (current.request) {
var gr = new GlideRecord('sc_request');
// Retrieve the sc_request record associated with the current task
if (gr.get(current.request)) {
// Check if the requested_for field is populated
if (gr.requested_for) {
var requestedFor = new GlideRecord('sys_user');
// Retrieve the user record associated with requested_for
if (requestedFor.get(gr.requested_for)) {
// Update the custom field with the department of the requested_for user
current.u_requestor_department = requestedFor.department;
} else {
gs.info('User record not found for requested_for: ' + gr.requested_for);
}
} else {
gs.info('Requested_for field is empty in request: ' + current.request);
}
} else {
gs.info('Request record not found: ' + current.request);
}
} else {
gs.info('Request reference is empty on catalog task: ' + current.sys_id);
}
})(current, previous);
I hope my answer helps you to resolve the issue if yes please mark my answer helpful and correct.
thank you
rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:25 AM
Have you tried with set values section of business rule ? you may not need script for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:41 AM
Yeah, did that!
But that as well didn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:50 AM
hi @BijoyDeb
Since you are trying to update the field based on values from another table, you should use an after Business Rule to ensure the record is saved and available for reading.
(function executeRule(current, previous /*null when async*/) {
// Check if the current record is valid and has a request reference
if (current.request) {
var gr = new GlideRecord('sc_request');
// Retrieve the sc_request record associated with the current task
if (gr.get(current.request)) {
// Check if the requested_for field is populated
if (gr.requested_for) {
var requestedFor = new GlideRecord('sys_user');
// Retrieve the user record associated with requested_for
if (requestedFor.get(gr.requested_for)) {
// Update the custom field with the department of the requested_for user
current.u_requestor_department = requestedFor.department;
} else {
gs.info('User record not found for requested_for: ' + gr.requested_for);
}
} else {
gs.info('Requested_for field is empty in request: ' + current.request);
}
} else {
gs.info('Request record not found: ' + current.request);
}
} else {
gs.info('Request reference is empty on catalog task: ' + current.sys_id);
}
})(current, previous);
I hope my answer helps you to resolve the issue if yes please mark my answer helpful and correct.
thank you
rajesh