How to set 'opened by' & 'request for' by in request, RITM, Task when catalog is created by a script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 04:01 AM
Hi All, I am creating a catalog request by a business rule. Now the problem is scipt is automatically setting 'opened by' & 'requested for' by script writer's user id. How can I set requested for & opened by in request, RITM, Task when catalog is created by a script? Thanks, Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 04:07 AM
Hi Ashwani,
A before insert business rule on sc_request table with below script should help.
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', current.sys_id);
grRITM.query();
while (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.requested_for)) { //considering requested_for is a variable on form & is not empty
current.requested_for = grRITM.variables.variable_name_for_requested_for;
current.opened_by = grRITM.variables.variable_name_for_opened_by;
}
grRITM.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 04:14 AM
Hi,
Business Rule
When: after
Insert/Update/Delete: true
Condition: <your_condition_here>
createRequest();
function createRequest() {
//Create Request
var cart = new Cart();
//substitute your cat item
var item = cart.addItem('<catalog item sys_id>');
//Set Variables in your Cart Item
//substitute your req for
cart.setVariable(item, 'requested_for','<req_for sys_id>');
cart.setVariable(item, 'opened_by','<opened by sys_id>');
cart.setVariable(item, 'request_short_description', 'Created from Business Rule');
cart.setVariable(item, 'request_description', 'Created from Business Rule');
cart.setVariable(item, 'request_type', 'others');
var rc = cart.placeOrder();
cart.description = 'servicenowelite.com';
var rc = cart.placeOrder();
gs.addInfoMessage('Request Item Created: ' + rc.number);
}
Create a workflow for the item, set the values of opened by and requested for as soon as the workflow runs:
current.requested_for= current.variables.requested_for;
current.opened_by= current.variables.opened_by;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2019 02:19 AM
Hello,
Please check the default value of the fields "Request for" and "Opened by" and update the dynamic default value as needed.
Regards,
Khadija