Populate a variable fetching data from multi row variable set

sibasundarsahoo
Tera Contributor

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());
}

 

 

@Allen Andreas @Pradeep Sharma @Community Alums @Anurag Tripathi @Mark Roethof 

1 REPLY 1

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Try to add some debugging. With that you will quickly see is the script triggered at all, if so until where it works, from where it breaks, etc.. That way, within minutes you know from where to proceed. Without debugging, you could be stuck on something like this for hours. Really unnecessary. 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn