- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 05:22 PM
Using a BR on the sys_user table to invoke some pre-filled onboarding items. Code is working in that my items are being created, however cant seem to figure out how to set short_description of the 'parent' sc_request and items.
this is my BR, with just part of 1 item.
how do you set the fields on the actual records from here?
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var usrID = current.sys_id;
var usrMan = current.manager;
var usrLoc = current.location;
var usrStart = current.u_start_date;
launchOnBoarding(usrID);
function launchOnBoarding(usrID) {
gs.include('Cart');
var cart = new Cart();
var loginID = cart.addItem('78638f924fcc4340d73ed49f0310c7d8');//login ID
cart.setVariable(loginID,'access_requested','New');
cart.setVariable(loginID,'building_location',usrLoc);
cart.setVariable(loginID,'colleague_start_date',usrStart);
cart.setVariable(loginID,'requested_for',usrID);
cart.setVariable(loginID,'requested_by',usrMan);
cart.update();
var rc = cart.placeOrder();
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 05:55 PM
Here the variable "rc" will have the newly created REQXXXX.
So, after calling placeOrder(), run query against REQ or RITM as necessary and pass REQXXXX using the variable "rc" and you can update short description from that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 05:55 PM
Here the variable "rc" will have the newly created REQXXXX.
So, after calling placeOrder(), run query against REQ or RITM as necessary and pass REQXXXX using the variable "rc" and you can update short description from that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 08:20 PM
Awesome!
Got that working.
Last thing that is giving me heartache, is I am trying to assign the RITM to an Order Guide record.
Is this even possible? reason is I have another workflow script that looks for certain order guides and skips some approvals. might need to find another way to identify these requests, was hoping to cheat a little here and just use the field.
I put this at the bottom of my script. I am getting the RITM.number in my logs, but the field fails to be set, ive tried sys_id, Display value..
any ideas?
cart.update();
var rc = cart.placeOrder();
var req = new GlideRecord('sc_request');
req.addQuery('number',rc.number);
req.query();
while (req.next()){
rc.short_description='OnBoarding Request for '+usrNm;
}
var item = new GlideRecord('sc_req_item');
item.addQuery('request',rc.sys_id);
item.query();
while (item.next()){
item.order_guide='b50c2db9db10bf803f789b3c8a9619a5';//Onboarding Order Guide SysId
gs.log('HELLOWORLD'+item.number);
}
// item.update();
rc.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 08:36 PM
I needed the update(), and my brackets seemed to be off.
this worked:
var item = new GlideRecord('sc_req_item');
item.addQuery('request',rc.sys_id);
item.query();
while (item.next()){
item.order_guide='b50c2db9db10bf803f789b3c8a9619a5';//CSR Onboarding
gs.log('HELLOWORLD'+item.number);
item.update();
}
rc.update();
}