How to populate Requestor Details in variables of MRVS?

rkreddy
Giga Expert

Hi All,

Hope everyone is doing good.

I am working on a catalog form with Variables,

Name (reference to User table), Department, Work Location, Telephone, Email. When value changes in Name variable, all the other variables get populated automatically if the user in Name variable has that values exist. If not, we are allowing users to manually enter values in Department, work location, telephone, email variables.

We have a MRVS with the same variables as mentioned above.

Now, We have a checkbox variable on the same form with name "Self". When user checks it to true, all the values in the Name, Department, work location, telephone, email should be copied to variables in MRVS. If he unchecks, the values should get cleared (only the row should get deleted which is populated when the variable is checked). This should work on change of both Name and Self variables.

Thank you.

1 ACCEPTED SOLUTION

@rkreddy 

Done and working fine in native

please check below output

find_real_file.png

Please mark my response as correct and close the question.

Regards
Ankur

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

View solution in original post

58 REPLIES 58

Hi @Ankur Bawiskar ,

alert('length' + parser.length);

find_real_file.png

 alert(JSON.stringify(obj1));

find_real_file.png

Hi,

before your for loop that string should be JSON object and not string

you already strinfigied details1 so don't do again

update as this

var finalArr = [];
        var parser = JSON.parse(details1);
		alert (parser);
alert(parser.length);

Regards
Ankur

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

Hi @Ankur Bawiskar ,

I have modified it, because if we have the script like you said above, parser is not showing any values. Getting like below:

alert(parser):

find_real_file.png

alert(parser.length): 1

 

If we change like below, parser is showing the values in variables:

var finalArr = [];
        var parser = JSON.parse(JSON.stringify(details1));
		alert (parser);

Hi,

so now it would go inside and get the object and parse it

do this directly

 var obj1 = parser[i];

    if (obj1.attendee_name.toString() != toRemove.toString()) {
        finalArr.push(obj1);
    }

Regards
Ankur

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

Hi @Ankur Bawiskar ,

Can I change like below:

var finalArr = [];
var parser = JSON.parse(details1);
for (var i = 0; i < parser.length; i++) {
var obj1 = parser[i];
if (obj1.attendee_name.toString() != toRemove.toString()) {
finalArr.push(obj1);
}
}

But obj1 is getting no values right?