To display contractor's names from multi row variable set in short description.

Bidhan_Singha
Tera Contributor

Hello,

I need to display the contractor's names(max limit=5) from a multi row variable set in the short description based on the type of access requested in the catalog form. I have written a code but it is not executing.

 

if(current.variables.type_of_access=="New Contractor Access"){
    var mrvs_1 = current.variable_set.new_contractor_access;
   
    var desc_1='';
    for (var i = 0; i < mrvs_1.length; i++) {
    desc_1+= current.variables.type_of_access.getDisplayValue() + " for " + mrvs_1[i].first_name + "\n";
    }
    current.short_description = desc_1 +'\n\n';
    }

    else if(current.variables.type_of_access=="Extend a Contractors Access"){
    var mrvs_2 = current.variable_set.extend_contractor;
   
    var desc_2='';
    for (var j = 0; j < mrvs_2.length; j++) {
    desc_2+= current.variables.type_of_access.getDisplayValue() + " for " + mrvs_2[j].extend_contractor_name + "\n";
    }
    current.short_description = desc_2 +'\n\n';
    }

    else if(current.variables.type_of_access=="Remove Contractors Access"){
    var mrvs_3 = current.variable_set.remove_contractor;
   
    var desc_3='';
    for (var k = 0; k < mrvs_3.length; k++) {
    desc_3+= current.variables.type_of_access.getDisplayValue() + " for " + mrvs_3[k].remove_contractor_name + "\n";
    }
    current.short_description = desc_3 +'\n\n';
    }

    else if(current.variables.type_of_access=="Update Contractors Details"){
    var mrvs_4 = current.variable_set.update_contractors_details;
   
    var desc_4='';
    for (var l = 0; l < mrvs_4.length; l++) {
    desc_4+= current.variables.type_of_access.getDisplayValue() + " for " + mrvs_4[l].update_contractor_name + "\n";
    }
    current.short_description = desc_4 +'\n\n';
    }
2 REPLIES 2

BrandyN11
Mega Contributor

Hi,

 

You can ensure your code executes, verify that the variable sets are correctly referenced and that the loop conditions are properly set. Also, check if the type_of_access variable is correctly capturing the user’s input. If issues persist, consider debugging with console logs or seeking help from a developer familiar with the platform you’re using.

Brad Bowman
Kilo Patron
Kilo Patron

This is a good first attempt.  Have you added log statements inside each if block to confirm that the script is running, and check field/variable values?  SInce you are using 'current' is this script in a workflow Run Script activity or Business Rule?  Try changing variable_set to variables, and using getRowCount(), and a catch-all 'else', so it would look more like this:

gs.info('myScript: running');
if (current.variables.type_of_access == "New Contractor Access") {
	gs.info('myScript new:' + current.variables.type_of_access);
    var mrvs_1 = current.variables.new_contractor_access;
	var rowCount_1 = mrvs_1.getRowCount();
	var desc_1 = '';
	for(var i=0; i<rowCount_1; i++){
		var row_1 = mrvs_1.getRow(i); 
        desc_1 += current.variables.type_of_access + " for " + row.first_name + "\n";
    }
    current.short_description = desc_1 + '\n\n';
} else if (current.variables.type_of_access == "Extend a Contractors Access") {
	gs.info('myScript extend:' + current.variables.type_of_access);
    var mrvs_2 = current.variables.extend_contractor;
	var rowCount_2 = mrvs_2.getRowCount();
	var desc_2 = '';
	for(var j=0; j<rowCount_2; j++){
		var row_2 = mrvs_2.getRow(j);
        desc_2 += current.variables.type_of_access + " for " + row.extend_contractor_name + "\n";
    }
    current.short_description = desc_2 + '\n\n';
} else if (current.variables.type_of_access == "Remove Contractors Access") {
	gs.info('myScript remove:' + current.variables.type_of_access);
    var mrvs_3 = current.variables.remove_contractor;
	var rowCount_3 = mrvs_3.getRowCount();
	var desc_3 = '';
	for(var k=0; k<rowCount_3; k++){
		var row_3 = mrvs_3.getRow(k);
        desc_3 += current.variables.type_of_access + " for " + row.remove_contractor_name + "\n";
    }
    current.short_description = desc_3 + '\n\n';
} else if (current.variables.type_of_access == "Update Contractors Details") {
	gs.info('myScript update:' + current.variables.type_of_access);
    var mrvs_4 = current.variables.update_contractors_details;
	var rowCount_4 = mrvs_4.getRowCount();
	var desc_4 = '';
	for(var l=0; l<rowCount_4; l++){
		var row_4 = mrvs_4.getRow(l);
        desc_4 += current.variables.type_of_access + " for " + row.update_contractor_name + "\n";
    }
    current.short_description = desc_4 + '\n\n';
} else {
	gs.info('myScript else:' + current.variables.type_of_access);
}