The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Mapping variables from catalog item to Requested item

FaizDev101
Tera Expert
  1. Created a variable named "priority" in catalog item as type (Select box)
  2. Added choices as High, medium and low with values 1, 2 and 3.

 

When submit the catalog item form with  priority choice according the value, Requested item (sc_req_item) "priority" field should change. How can I implement that ?

 

(Catalog item priority field)

FaizDev101_3-1681723013850.png

 

(Requested item priority field)

FaizDev101_0-1681722886906.png

 

 

(Note: The "priority" field in Requested item (sc_req_item) is not read only)

1 ACCEPTED SOLUTION

Upsilon
Giga Guru

Hello, 

You can use a BR (On create) to update and map cat_item priorities with sc_requested_item. Idealy you can use the same values for both and hide options that you don't need

Upsilon_0-1681724002250.png

 

(function executeRule(current, previous /*null when async*/ ) {
	// If cat_item choices == sc_req_item choices
current.priority= current.variables.priority;
	//else If cat_item choices != sc_req_item choices
var	priority_map={"high": 1,"low": 5};
	
	current.priority= priority_map[current.variables.priority];
		

})(current, previous);

 

Regards,

 

View solution in original post

6 REPLIES 6

Upsilon
Giga Guru

Hello, 

You can use a BR (On create) to update and map cat_item priorities with sc_requested_item. Idealy you can use the same values for both and hide options that you don't need

Upsilon_0-1681724002250.png

 

(function executeRule(current, previous /*null when async*/ ) {
	// If cat_item choices == sc_req_item choices
current.priority= current.variables.priority;
	//else If cat_item choices != sc_req_item choices
var	priority_map={"high": 1,"low": 5};
	
	current.priority= priority_map[current.variables.priority];
		

})(current, previous);

 

Regards,

 

Ankur Bawiskar
Tera Patron
Tera Patron

@FaizDev101 

you must be using workflow or flow for your catalog item

in that workflow run script do this

current.priority = current.variables.priority; // ensure choice values are same for field and the variable

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

is it possible to use any onsubmit client script ?

@FaizDev101 

onSubmit on catalog item won't work as by that time RITM is not yet generated

It can be done only from Workflow or Flow which is linked to your catalog item

OR

you can use before/after insert BR on RITM table -> This I won't recommend as you can directly add the logic in your workflow or flow and no need to create an extra component i.e. BR

If my response helped please mark it correct and close the thread so that it benefits future readers.

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