IMPOSSIBLE onChange Client Script on MRVS Multi Row Variable Set

Mauro15
Tera Expert

Hi all, it seems that this is impossible to achieve.

 

I need to run a UI Script (in the Service Portal) when something changes to a MRVS (Multi Row Variable Set), but it seems that MRVS are not shown in the dropdown menu where I select the Variable (screenshot below).

 

NB: I don't need to set "Applies to" to a Variable Set, I need to apply the script to the Catalog Item.

Because when the content of the MRVS changes, I need to take the full content of it via script and use to change the value of another variable of the content item, which is not part of that MRVS.

 

Is this possible at all?

If not, any workarounds?

 

Mauro15_0-1665674394957.png

 

Thanks!

Mauro

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Mauro,

Here's one way to do this.

1) create 2 Catalog Item variables.

1a) A simple multi-line text variable.  This can be hidden with a UI Policy or Client Script, and may not be needed - see below.

1b) Type=Custom, Type Specifications, Widget = <Click the New button to create a new Widget>.

   Paste this text into the Client controller field, and update where commented:

api.controller=function($scope) {
	/* widget controller */
	var c = this;
	var mrvsName = 'mrvs_internal_name'; // replace with your MRVS internal name
	
	$scope.$watch(function() {
		return $scope.page.g_form.getValue(mrvsName);
	}, function(value) {
		g_form = $scope.page.g_form;
		g_form.setValue('multi_line_text_variable_name', value); //replace with your text variable name
	});
};

2) Trigger your onChange Catalog Client Script when the variable in 1A changes.  An alternative, though it's hiding the code a bit so will drive someone nuts later is to just do whatever you were going to do in that script in the widget script instead of setting the value of a holding variable.

 

So in summary, in Service Portal whenever a row is Added, Deleted, or Edited, the custom variable widget will update the multi-line text variable (or whatever) since it is "watching" for a change.

   

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Hi Mauro,

Here's one way to do this.

1) create 2 Catalog Item variables.

1a) A simple multi-line text variable.  This can be hidden with a UI Policy or Client Script, and may not be needed - see below.

1b) Type=Custom, Type Specifications, Widget = <Click the New button to create a new Widget>.

   Paste this text into the Client controller field, and update where commented:

api.controller=function($scope) {
	/* widget controller */
	var c = this;
	var mrvsName = 'mrvs_internal_name'; // replace with your MRVS internal name
	
	$scope.$watch(function() {
		return $scope.page.g_form.getValue(mrvsName);
	}, function(value) {
		g_form = $scope.page.g_form;
		g_form.setValue('multi_line_text_variable_name', value); //replace with your text variable name
	});
};

2) Trigger your onChange Catalog Client Script when the variable in 1A changes.  An alternative, though it's hiding the code a bit so will drive someone nuts later is to just do whatever you were going to do in that script in the widget script instead of setting the value of a holding variable.

 

So in summary, in Service Portal whenever a row is Added, Deleted, or Edited, the custom variable widget will update the multi-line text variable (or whatever) since it is "watching" for a change.

   

Hi Brad, thanks a lot for your help. This is indeed a great answer and a confirmation that MRVS are excluded from the OOB onChange Client Scripts. I will make this widget and test it, thanks again, much appreciated.

Mauro

This is so useful, thanks for taking the time to post it here!

Thanks a Brad for the information. Any way we can find out that the change was due to addition of a row or the row was edited ???