Sort an MRV

Dazler
Mega Sage

Hi,

 

I have an MRV on my catalog item form and I need to be able to sort them.  There are 2 variables in the MRV and below is an example.

 

mrv.png

 

Is there a way to sort the mrv by default, based on the Provide Drive Label?

 

Or am I able to sort this when Flow Designer runs?  If so, how can I sort it in Flow?

1 ACCEPTED SOLUTION

Dazler
Mega Sage

I figured out how to sort an MRV by variable.  Here is my script, in case someone could use it.

 

(function execute(inputs, outputs) {

var mrvs;
var itemID = inputs.record_sysid;
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
    mrvs = ritmGR.variables[inputs.variable_set_name];
}

var mrvSort = JSON.parse(mrvs);

var sortedArray = mrvSort.sort(function(a, b){
var x = a[inputs.variable_to_sort];
var y = b[inputs.variable_to_sort];
return x < y ? -1 : x > y ? 1 : 0;
});

outputs.sorted_mrv_array = JSON.stringify(sortedArray);
  
})(inputs, outputs);

View solution in original post

1 REPLY 1

Dazler
Mega Sage

I figured out how to sort an MRV by variable.  Here is my script, in case someone could use it.

 

(function execute(inputs, outputs) {

var mrvs;
var itemID = inputs.record_sysid;
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
    mrvs = ritmGR.variables[inputs.variable_set_name];
}

var mrvSort = JSON.parse(mrvs);

var sortedArray = mrvSort.sort(function(a, b){
var x = a[inputs.variable_to_sort];
var y = b[inputs.variable_to_sort];
return x < y ? -1 : x > y ? 1 : 0;
});

outputs.sorted_mrv_array = JSON.stringify(sortedArray);
  
})(inputs, outputs);