Variable Set with Client Script (onLoad)

EliaquimS
Tera Contributor

Good morning! How do I get a value from within the multirow variable and send it to a variable that is not in the multirow?

EliaquimS_0-1734696801569.png

 

11 REPLIES 11

Community Alums
Not applicable

Hi @EliaquimS ,

 

To get a multi-row variable set value in a client script, use the g_form.getMultiRowValues('variable_set_name') function, which returns an array of objects where each object represents a row in the multi-row variable set, allowing you to access the values of each field within that row individually; make sure to replace "variable_set_name" with the actual internal name of your multi-row variable set. 
 
 

 

function getMRVSValues() {

    var mrvsData = g_form.getMultiRowValues('u_my_mrv_set'); // Assuming "u_my_mrv_set" is the internal name of your MRVS



    for (var i = 0; i < mrvsData.length; i++) {

        var row = mrvsData[i];

        var field1Value = row.u_field1; // Accessing the value of the "u_field1" field in the current row

        var field2Value = row.u_field2; // Accessing the value of the "u_field2" field in the current row

        // ... perform further operations with the values

    }

}

 

 

This doesn't work my friend!

This doesn't work my friend!

Runjay Patel
Giga Sage

Hi @EliaquimS ,

 

You can use onload client script to auto populate the MRVS data.

function onLoad() {
    //Type appropriate comment here, and begin script below




    var data = [{
            "MaterialID": "10000",
            "Description": "Test",
            "Quantity": 4
        },
        {
            "MaterialID": "100001",
            "Description": "test2",
            "Quantity": 1
        }
    ];



    // Get the MRVS variable name
    var mrvsVariableName = 'product_parameters'; // Replace with your actual variable name
    var newRecord = [];
	
    // Loop through the array and add records to the MRVS
    data.forEach(function(item) {
        // Create a new record in the MRVS
        newRecord.push({
            "material_id": item.MaterialID,
            "description": item.Description,
            "quantity": item.Quantity
        });
        
        // Push the new record to the MRVS
        g_form.setValue(mrvsVariableName, JSON.stringify(newRecord));
    });
}

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

I don't want to populate my multirow. I want a field filled in my multirow, when filled, to automatically populate another variable that is outside the multirow. Got it?