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,

to get display value in portal use this

var valuePortal = g_form.getDisplayValue('requester');

what came in alert for details1 value?

Regards
Ankur

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

Hi @Ankur Bawiskar ,

what came in alert for details1 value?

the script you updated is same as in before thread, I don't see any alert. But I tried by placing alert(details). It is showing values in the variables.

I have tried using getDisplayValue, but if I am using that, onLoad the value is showing null, the value is getting displayed only when self is checked to true.

onLoad:

find_real_file.png

find_real_file.png

Hi,

in your else condition you need to get the MRVS JSON string so that you can iterate over it and then remove specific object from array

Regards
Ankur

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

Hi @Ankur Bawiskar ,

updated like below but no luck.

function onChange(control, oldValue, newValue, isLoading) {
	var self = g_form.getValue('self');
	var selfDetails = [];
    var details = '';

    var obj = {};
   
    obj["attendee_name"] = g_form.getDisplayBox('u_requested_for').value;
    obj["email_address"] = g_form.getValue('u_email');
    obj["department"] = g_form.getValue('u_department');
    obj["u_work_location"] = g_form.getValue('work_location');
    obj["telephone_number"] = g_form.getValue('u_telephone');
    selfDetails.push(obj);
    details = JSON.stringify(selfDetails);
	if (newValue != '' && self == 'true') {
    g_form.setValue('attendees_information', details);
    }
	else if (newValue == '' && self == 'false'){
	obj["attendee_name"] = g_form.getDisplayBox('u_requested_for').value;
    obj["email_address"] = g_form.getValue('u_email');
    obj["department"] = g_form.getValue('u_department');
    obj["u_work_location"] = g_form.getValue('work_location');
    obj["telephone_number"] = g_form.getValue('u_telephone');
    selfDetails.push(obj);
    details = JSON.stringify(selfDetails);
	var toRemove = g_form.getDisplayBox('u_requested_for').value;
	var finalArr = [];
	var parser = JSON.parse(details);
	for(var i=0;i<parser.length;i++){
		var obj1 = parser[i];
		var newParser = JSON.parse(JSON.stringify(obj1));
			if(newParser.attendee_name != toRemove){
			finalArr.push(obj1);
	}
}
}
}

Hi,

unless you add alert statements it would be difficult to know where the script is breaking

Regards
Ankur

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