How to map a variable requested for to the RITM Field requested for

BCELSTEI
Tera Expert

Hello everybody,

I d like to know how to push the requested for variable on the sc_req_item.requested for field 

my requested for variable is in set variable I don't know if it can be trouble.

 

find_real_file.png

I already searched in the community and it's not working

https://community.servicenow.com/community?id=community_question&sys_id=00c00b65db98dbc01dcaf3231f9619b6&view_source=searchResult

 

I created a BR on before based on my catalog element and it's working for the other field (self service,telephone and description)

(function executeRule(current, previous /*null when async*/) {

// Add your code here

current.requested_for=current.variables.requested;
current.contact_type='self-service';
current.u_t_l_phone_pro=current.variables.telephone;current;
current.description=current.variables.description;

})(current, previous);

 

Thanks a lot for your help

Have a good day

Barbara CS

1 ACCEPTED SOLUTION

mr18
Tera Guru
Tera Guru

you can achieve this from workflow.

In the workflow, use Run script and try below code

var req = new GlideRecord("sc_request");
req.addQuery("sys_id", current.request);
req.query();
if(req.next()) {
req.requested_for = current.variables.<variable name>;
req.update();
}

View solution in original post

5 REPLIES 5

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

There does not exists any Requested for field on RITM it is on REQ table.

Replace

current.requested_for=current.variables.requested;

with

current.request.requested_for=current.variables.requested;

for a check

Above would work if you are using it in Run script activity of workflow.

For Business rule use below.

(function executeRule(current, previous /*null when async*/) {

// Add your code here
//Goes to REQ table to update reqeusted for which will be reflected at RITM level
var getreq=new GlideRecord('sc_request');
getreq.addQuery('sys_id',current.request);
getreq.query();
if(getreq.next())
{
getreq.requested_for=current.variables.requested;
getreq.update();
}

current.contact_type='self-service';
current.u_t_l_phone_pro=current.variables.telephone;current;
current.description=current.variables.description;

})(current, previous);

Hello and thanks for your help

it s not working on my database current.request.requested_for=current.variables.requested.

On the following screen with your business rule I haven't got  any value in requested for in the screen order status

find_real_file.png

 

but when i use this script in business rules before there's a the good value in "Requested for"   it'working but my other variables are not updated (phone, description) on RITM

 

find_real_file.png

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here

if(current.variables.requested){
var grREQ = new GlideRecord('sc_request');
grREQ.get(current.getValue('request'));
grREQ.setValue('requested_for', current.variables.requested);
grREQ.update();
gs.log(grREQ, " Requested For");
}

 

current.contact_type='self-service';
current.u_t_l_phone_pro=current.variables.telephone;current;
current.description=current.variables.description;

 

})(current, previous);

 

 

I don't know where is the mistake on my param or that solution seems to be good but my other variables are not updated I have to learn about developpment too

 

Thank for your help

 

 

mr18
Tera Guru
Tera Guru

you can achieve this from workflow.

In the workflow, use Run script and try below code

var req = new GlideRecord("sc_request");
req.addQuery("sys_id", current.request);
req.query();
if(req.next()) {
req.requested_for = current.variables.<variable name>;
req.update();
}