Populate a variable fetching data from multi row variable set

1_DipikaD
Kilo Sage

API Variable should be populated in the following format <Fetch the values from MRVS>:

 <member[1].email>;;

<member[2].email>;;

and so on.

No. of values in MRVS -> no .of lines in API variable.

 

Name of the MRVS is Members of the distribution list.

Please find the attachment.

 

I tried this on change catalog client script  on changing the MRVS value but not able to execute this :-

function onChange(control, oldValue, newValue, isLoading) {
    // Check if the form is still loading or the new value is empty
    if (isLoading || newValue == '') {
        return; // If true, exit the function
    }

    // Retrieve the value of the 'members_of_the_distribution_list' field
    var mvrsValue = g_form.getValue("members_of_the_distribution_list");
    // Parse the JSON value into an array
    mvrsValue = JSON.parse(mvrsValue);

    // Create an empty array to store the member values
    var multilineTextValue = [];
    // Loop through each member in the 'members_of_the_distribution_list' field
    for (var i = 0; i < mvrsValue.length; i++) {
        // Push each member value into the multilineTextValue array
        multilineTextValue.push(mvrsValue[i].member);
    }

    // Set the value of the 'api_variable' field to a comma-separated string of member values
    g_form.setValue("api_variable", multilineTextValue.toString());
}

 

 

@Ankur Bawiskar

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@1_DipikaD 

so you want onChange or on addition of row you want to populate the multi-line variable

onChange on MRVS doesn't work like that

you need to detect the add/remove action and then have the logic

check this link and enhance

MRVS detect when a row is removed or deleted 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@1_DipikaD 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader