Set current.variables from RITM form

Jan Janou_ek
Tera Expert

Hello guys!

I want to use RITM "stage", "assignment_group" and "assigned_to" for catalog policies to show some variables during the fulfillment process. I used this solution in my last job but now I am trying to set it up again and I am not able to set current values.

I have three variables on my Item as you can see, callled "stage_read_only", "fulfillment_group" and "assigned_to" and BR which takes current values from RITM. It takes actual values and I am able to print it to the log but not set to the variables. Dont know where the fault is.

I´ve also tried to rename variable "assigned_to" to "fulfiller" but no change.

Thank you!

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

var stage = current.stage.getDisplayValue();
	current.variables.stage_read_only = stage;
	gs.log('Stage is: ' + stage);
	
	var afg = current.assignment_group.getDisplayValue();
	current.variables.fulfillment_group = afg;
	gs.log('Assignment group is: ' + afg);
	var assignedto = current.assigned_to.getDisplayValue();
	current.variables.assigned_to = assignedto;
	gs.log('Assigned to is: ' + assignedto);
})(current, previous);

 

edit: I forgot to say that BR is after Insert / update.

4 REPLIES 4

Aman Kumar S
Kilo Patron

Hey,

Instead of current.variables.assigned_to try using current.variables[field_name]

 

Below article highlights that:

Display or Modify ritm variables from script

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Hi Aman!

Im not sure if I got it right but when I try

var stage = current.stage.getDisplayValue();
	current.variables[stage_read_only] = stage;

then I have this error in the log:

com.glide.script.RhinoEcmaError: "stage_read_only" is not defined.
sys_script.80b3c2ce970c1d10b8a1fef3a253af38.script : Line(4) column(0)
1: (function executeRule(current, previous /*null when async*/) {
2:
3: var stage = current.stage.getDisplayValue();
==> 4: current.variables[stage_read_only] = stage;
5: gs.log('Stage is: ' + stage);
6:
7: var afg = current.assignment_group.getDisplayValue();

Jan Janou_ek
Tera Expert

LOL, my bad, just need to add "current.update();" and it works. So final code is:

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

var stage = current.stage.getDisplayValue();
	current.variables.stage_read_only = stage;
	var afg = current.assignment_group.getDisplayValue();
	current.variables.fulfillment_group = afg;
	var assignedto = current.assigned_to.getDisplayValue();
	current.variables.assigned_to = assignedto;
	current.update();
})(current, previous);

Please mark response as helpful/correct so the thread can be closed

Best Regards
Aman Kumar