Plugging inputs into a script in a flow action

kchorny
Tera Guru

I am trying to create a flow action that will take some inputs and perform some operations using those inputs.

In this case, I need to copy some values from one MRVS into another MRVS. I need to do this several times in different flows, so am hoping it's possible to do it with a custom action and varying inputs.

 

For this example, assume all of my variables starting with 'input' are inputs into the action. The inputs would be plugged into the script where I've added the input in a bracket

(aside from the index variables i and j).

 

Is this possible? If so, how to construct this script?

 

Edit: this works in a background script. I updated the script below to reflect the changes I had to make to get it to work. I haven't tried it in an action yet.

 

 

 

var inputsritm = '53e687cf1bb46590fbbbeaccac4bcbdb';
var inputsmrvs1 = 'add_connections_on_new_network_v2';
var inputsmrvs2 = 'mrvs_update_faceplate_install_info';
var inputsvars1 = 'mrvs_1_row_number,mrvs_1_select_room';
var inputsvars2 = 'mrvs_2_row_number,mrvs_2_select_room';
var inputsconditionvar = 'mrvs_1_faceplate_install_needed';
var inputscondition = 'true';

var ritm = inputsritm;
var r = new GlideRecord('sc_req_item');
r.get(ritm);
var mrvs1 = r.variables[inputsmrvs1]; //this works
var mrvs2 = r.variables[inputsmrvs2]; //this works
var varsToCopyFrom = inputsvars1.split(',');
var varsToCopyTo = inputsvars2.split(',');
var varToCheck = inputsconditionvar;
var conditionValue = inputscondition;
var json = JSON.parse(mrvs1);
for (var i in json) {
	if (json[i][varToCheck] == [conditionValue]) {
		var newRow = mrvs2.addRow();
		for (var j=0;j<varsToCopyFrom.length;j++) {
			newRow[varsToCopyTo[j]] = json[i][varsToCopyFrom[j]];
		}		
	}
}
r.update();

 

 

 

0 REPLIES 0