Populate "Requested for" and "Opened for" on REQUEST and RITM

snowenthusiast
Tera Contributor

Hi,

Pretty basic and straightforward question - how do we populate "Requested for" field on REQUEST and "Opened for" field on REQUESTED ITEM (RITM) when a catalog item is submitted by and end user. I've seen business rule approaches but this shouldn't be that complex. I mean, it should be straightforward to push these details from an end user form to requested item (without any scripting)?

We have to do this across all items in the catalog. Any insight will be helpful.

Thanks.

3 REPLIES 3

sreedhar kota
Mega Guru

Hello there,

 

write a catalog client script  something like this:

var req = new GlideRecord('sc_request');
req.addQuery('sys_id',current.request);
req.query();
if(req.next()){
req.requested_for = current.variables.user; //current.variables.user is to read the user name from catalog form. same like opend, you can pick other variable value.
req.update();
}

 

sreedhar

Ahmmed Ali
Mega Sage

Hello,

 

Have a variable set with variable as requested_for (basically for maintaining same variable name in all items) and include the variable set in all items (currently if variable name for requested for is same in all items then no need of this).

 

Have business rule in requested item table as.

//to update RITM

current.opened_for = current.variables.requested_for;//update variable name as in your item

..To update request

var req = new GlideRecord('sc_request');
req.addQuery('sys_id',current.request);
req.query();
if(req.next()){
req.requested_for = current.variables.requested_for;//update variable name as in your item
req.update();
}

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Angshuman3
Mega Guru

Hi,

This can be done pretty simply using the Workflow created on the sc_req_Item table by creating a 'Run Script' Activity. In the Activity use the below code :-

var request = current.request.getRefRecord();
request.opened_by = current.variables.opened_by.toString();
request.requested_for = current.variables.requested_for.toString();
request.update();

current.opened_by = current.variables.opened_by.toString();

Hope this helps.

Mark the answer as correct/helpful if you are satisfied.

Thanks,
Angshuman