How to copy the variables from RITM(sc_req_item) to Request "Req"(sc_request)

Service Manager
Kilo Guru

Hi All,

I would like to copy one of the variable "Egroup" (single line text) from RITM table to Req table

I wrote Business Rule On after Insert and specified the catalog item in filter condition

(function() {

//get the gliderecord for the parent request

var req = new GlideRecord('sc_request');
if (req.get(current.request)) {
req.eGroup = current.variables.x_egroup;
gs.addInfoMessage("Hello World");
req.update();
}
})();

FYI : I created BR on scoped application and a new field egroup on sc_request(request) table as a scoped field.

 

Thanks

1 ACCEPTED SOLUTION

Actually 
I tried that on global application and it worked successfully with below script 

BR async 

 

(function executeRule(current, previous /*null when async*/) {
var request =current.request.getRefRecord();
request.x_egroup = current.variables.egroup;

request.update();

})(current, previous);

 


Thanks

View solution in original post

5 REPLIES 5

Jon Barnes
Kilo Sage

"eGroup" can't be the column name on the request table. maybe you have a typo in your script? My guess is that eGroup is the variable name, so in that case, try:

req.setValue('x_egroup', current.variables.eGroup);

Hey,

I tried that way but unfortunately it didn't work
is it something related to scope application ?

because I believe sc_Request(request) table is on global application  and I created the field "x_egroup" on sc_Request(request) table and BR on (sc_req_item) request item table on scoped application.

Thanks

Hi @jon Barnes

The below BR worked for me on after and Insert. We were able to copy variable value to Req but two request were getting created One request with RITM and another Request without RITM

(function executeRule(current, previous /*null when async*/) {
var request =current.request.getRefRecord();
request.x_group = current.variables.eGroup;

request.update();

})(current, previous);

 

Thanks

HI,

Try to change the application on which your variable exists and try below code.Hope it will works.And if you want this for one particular item better to try this code in that particular item workflow.

var req = new GlideRecord('sc_request');
if(req.get(current.request.sys_id)) {

req.eGroup = current.variables.x_egroup; 
req.update();
}