copy catalog variables to RITM and REQ forms.

Priyanka Pawar1
Mega Expert

Hello All,

 

I am trying to copy a location catalog variable on Request item and request form.

I have written the below code.

I have a run activity on request item workflow which is trying to set the location variable on scratchpad.

 

Run script activity on workflow.

 find_real_file.png

Then I am running a after business rule on request item table to set the location variable value on request item form and request form’s filed called location.

 

 find_real_file.png

But this script is not working, I have tried multiple thing but unable to do so.

Can anyone help me over here?

 

Regards,

Priyanka

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

If I understand it correct you would like to update location field on RITM and Request using the location variable

Try the below script in Run script

//Update location field on RITM
current.location = current.variables.location;

//Update location field on Request
var gr = new GlideRecord("sc_request");
gr.addQuery("sys_id", current.request);
gr.query();
if (gr.next()) {
	gr.location = current.variables.location;
	gr.update();
}

View solution in original post

5 REPLIES 5

Dubz
Mega Sage

When i was testing adding RITM's via API i found that you have to add the variable in to the sc_item_option table and then relate it to the RITM in the sc_item_option_mtom table. This is the script i was testing with in a fix script. You could probably co-opt it somehow but it might be better to run it in a script activity in the workflow rather than in a BR, you need to update the record to trigger the BR whereas you can trigger it however you want in the WF.

var itemGr = new GlideRecord("sc_req_item");
itemGr.initialize();
itemGr.cat_item = 'sys_id of catalog item';
itemGr.request = 'sys_id of master request';
itemGr.state = 1;
var reqItem = itemGr.insert();

var optionGr = new GlideRecord('sc_item_option');
optionGr.initialize();
optionGr.item_option_new = 'sys_id of variable';
optionGr.value = 'value or variable;
var itemID = optionGr.insert();

var relGr = new GlideRecord('sc_item_option_mtom');
relGr.initialize();
relGr.request_item = reqItem;
relGr.sc_item_option = itemID;
relGr.insert();

var startWF = new GlideRecord('sc_req_item');
if(startWF.get(reqItem)){
startWF.setForceUpdate(true);
startWF.update();
}

Subhadip Saman1
Mega Expert

Hi,

I am little bit confused! You are setting the value of location in a workflow scratchpad variable and then trying to use it in a business rule.. I don't think it will work, because only g_scratchpad variables are available for use in a business rule then also it should be initialized from a display BR.

Correct me if I am wrong.

Thanks,

Subhadip

Hello TheKid,

 

I have taken the reference from below link:-

https://docs.servicenow.com/bundle/london-application-development/page/script/useful-scripts/reference/r_AcsWrkflowSPBR.html

 

Please read it and let me know if i did anything wrong over here.

 

Regards,

Priyanka

dvp
Mega Sage
Mega Sage

If I understand it correct you would like to update location field on RITM and Request using the location variable

Try the below script in Run script

//Update location field on RITM
current.location = current.variables.location;

//Update location field on Request
var gr = new GlideRecord("sc_request");
gr.addQuery("sys_id", current.request);
gr.query();
if (gr.next()) {
	gr.location = current.variables.location;
	gr.update();
}