Move custom field value in ritm to approvers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 04:33 PM
Hello everyone
I need your help with the sysapproval_approver table. First I have a ritm (catalog item), and in this ritm I have a custom field (text field for comments). I would like to pass the value of this custom field to the comments field (highlated below) of the approvers through a Business Rule. But the script, and I have tried multiple ones, none have worked. Can anyone tell me if it can be achieved with a script or does it need to be done in a different way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 06:22 PM - edited 01-03-2024 06:24 PM
Hi @LuLe Game
You have the comments field as a Catalog Item variable OR a field on sc_req_item table?
If it's on catalog item as a variable, try this in a Before Insert BR on sysapproval_approver table.
In When to Run Section, select the conditions so that, the BR runs only for that specific Catalog Item (dot walk using show related fields in condition builder).
(function executeRule(current, previous){
var ritm = current.sysapproval;
var comments= ritm.variables.comments; //replace with your variable name
current.comments = comments;
}(current, previous);
If the field is at RITM table level, just change the script to the following one.
(function executeRule(current, previous){
var ritm = current.sysapproval;
var comments= ritm.u_comments; //replace with your field name
current.comments = comments;
}(current, previous);
Please mark my answer helpful and accept as a solution if it helped 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 08:11 AM
Hi,
I am not sure if this is the answer if this the right approach. The comments field is in sysapproval_approver table (image). The custom field (string) is in ritm table. What I want is to move the value from this field (sc_req_item) to the approvers (sysapproval_approver), specifically to the "Comments" field. I hope this could bring more light to this issue. Here is my code (that is not working) from the after Update BR in sc_req_item. I am using a specific record to make the change but my goal is every record that make changes to the custom field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 06:04 PM
@LuLe Game Understood now!
Update your code with the following one, let me know if it is not working.
var gr_approvalinfo = new GlideRecord("sysapproval_approver"); gr_approvalinfo.addEncodedQuery("state=requested^sysapproval=" + current.getUniqueValue() + "^ORdocument_id=" + current.getUniqueValue());
gr_approvalinfo.query();
while (gr_approvalinfo.next()) {
gr_approvalinfo.comments = current.getValue('u_customfield'); //custom field name
gr_approvalinfo.update();
}
Please mark my answer helpful and accept as a solution if it helped 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 06:23 PM
@LuLe Game I have tested the above code in My PDI, it's perfectly working fine.
See the screenshots below for, Business Rule configuration and Test results.
Anvesh