How to copy the variable field value in a Catalog Form to the Requested Item table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 10:16 PM - edited 10-06-2023 10:16 PM
I am trying to copy the field value for a variable - Requested For under a Catalog Form to the Requested Item - Requested For field.
My understanding is that the variable field - Requested For is in the Table sc_item_option_mtom but when I clicked on the Dependent Item for the field, it opened up into a new table - sc_item_option and it shows something like below.
The value refers to the user's sys_ID which I wanted to copy over to the field Requested For on the sc_req_item table.
Tried with the code below in Business Rules but its not working..
(function executeRule(current, previous) {
// Get the sc_req_item sys_id
var reqItemId = current.sys_id;
// Get the sc_item_option_mtom table for related records
var itemOptionMtom = new GlideRecord('sc_item_option_mtom');
itemOptionMtom.addQuery('request_item', reqItemId);
itemOptionMtom.addQuery('variable.name', 'common_ReqFor');
itemOptionMtom.query();
// Get related records
if (itemOptionMtom.next()) {
// Get the value of 'common_ReqFor' from the related record
var commonReqForValue = itemOptionMtom.value;
// Update requested_for field in the sc_req_item record with 'common_ReqFor' value
current.requested_for = commonReqForValue;
// Update sc_req_item record
current.update();
}
})(current, previous);
Appreciate if someone can help me on this..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 10:40 PM
Hi @Happy S
Creation BR is not the appropriate solution to copy variable value to RITM field name. Instead you can try using run script and set the value accordingly in the following way in the workflow.
current.field_name= current.variables.variable_name;
Please mark as Accepted Solution & HIT helpful.
BR, Sohith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 11:04 PM
Hi @Happy S
As my understanding, you want to set "Requested For" field on RITM with "Requested For" coming from Variable
Below things you need to consider
1.There are two Requested For fields on RITM
- Requested For - Local to RITM table (which OOTB in not present on RITM form)
- Requested For - Present on Request table & displayed on RITM form request.requested_for
So you can modify your script like below:
(function executeRule(current, previous) {
/*Get the Request sys id */
var request = current.request;
/*Glide record on Reuest table */
var grReq = new GlideRecord('sc_request');
grReq.addQuery('sys_id',request);
grReq.query();
if(grReq.next()){
grReq.requested_for = current.variables.<variable_name>;
grReq.update();
}
/*Update the requested for from ritm form */
current.requested_for = current.variables.<variable_name>;
})(current, previous);
You can do this using workflow also.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates