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,

now obj1 should have json object

try the above code now and share

Regards
Ankur

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

Sorry @Ankur Bawiskar , I didn't get you. Which code should I need to use ? Do I need to use for loop again?

Hi,

use this and share the updates

if it contains only 1 object then no for loop required

Regards
Ankur

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

rkreddy
Giga Expert

Hi @Ankur Bawiskar ,

I have modified like below,

parser is showing [object Object] and obj1 is showing undefined. The result is, the value in MRVS is not getting cleared when self is unchecked.

var finalArr = [];
var parser = JSON.parse(details1);
alert (parser);
var obj1 = parser[i];
alert(obj1);
if (obj1.attendee_name.toString() != toRemove.toString()) {
finalArr.push(obj1);

}
g_form.setValue('attendees_information', JSON.stringify(finalArr));
}

I have also checked with the below version, but the same result and obj1 is empty. 

var finalArr = [];
var parser = JSON.parse(JSON.stringify(details1));
alert (parser);
var obj1 = parser[i];
alert(obj1);
if (obj1.attendee_name.toString() != toRemove.toString()) {
finalArr.push(obj1);

}
g_form.setValue('attendees_information', JSON.stringify(finalArr));
}

Here we are not defining "i" anywhere right, var obj1 = parser[i] but we used i here.

Hi,

since your arr contains only 1 object no need for i

it should be parser[0];

var finalArr = [];
var parser = JSON.parse(details1);
alert (parser);
var obj1 = parser[0];
alert(obj1);
if (obj1.attendee_name.toString() != toRemove.toString()) {
finalArr.push(obj1);

}
g_form.setValue('attendees_information', JSON.stringify(finalArr));
}

Regards
Ankur

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