How to get the variable value

SNOW39
Tera Expert

Hi ,

I am trying to create a variable set that is visible only on sc_task, when the task is closed, it should pull the recurring price value mentioned when the catalog item is created (sc_cat_item). How to acieve this?

1 ACCEPTED SOLUTION

Hi,

ok so in the run script after the task is complete the script is added

please find the below code

Ensure you add current.setWorkflow(false);

current.variables.recurring_price = current.cat_item.recurring_price.toString();
current.setWorkflow(false);
current.update();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

27 REPLIES 27

Hi,

Can you share screenshot where in workflow you wrote that line?

you should set the value once task is closed; So I though you must be using after update BR on sc_task table

Please use after update BR on sc_task table

BR Condition: current.request_item.cat_item == 'yourCatalogItemSysId' && State is Closed

Script:

var ritm = new GlideRecord('sc_req_item');
ritm.get(current.request_item);

// while setting the value use setWorkflow(false) to avoid triggering BR

ritm.variables.recurring_price = ritm.cat_item.recurring_price.toString();
ritm.setWorkflow(false);
ritm.update();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

out of the box there is this business rule which restricts updating variable on RITM

BR Name: Disallow variable edit on RITM

URL: https://instanceName.service-now.com/nav_to.do?uri=sys_script.do?sys_id=d3a6ded24f331200fc11fa218110c771

For making this update work; please use this logic i.e. setWorkflow(false)

I assume BR is on sc_task table and proper condition is set i.e. it triggers only for your catalog item and when state changes to closed

Script below should work

// query for ritm table

var ritm = new GlideRecord('sc_req_item');
ritm.get(current.request_item);

// while setting the value use setWorkflow(false) to avoid triggering BR

ritm.variables.recurring_price = ritm.cat_item.recurring_price.toString();
ritm.setWorkflow(false);
ritm.update();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Can i not achieve this from workflow, when the task is complete.We already have a generic workflow so can i add a runscript ?

Hi,

replied to your comment where you mentioned the screenshot

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi We are trying to achieve this on SCTASK. Since it was mentioned not possibel on SCTASK we tried in RITM> Requirement is for SCTASK