MRVS Populate Client Script - Editing rows not retaining values

Umar Nasir
Tera Expert

Hello to the wonderful SN Dev Community.

I am having an issue with a Record Producer that contains a Multi-row Variable Set.
I am using a Script Include to populate the MRVS using multiple GlideRecord queries on a Script Include that gets called by an OnChange Client Script on the Record Producer. The values are able to be populated into the MRVS, however if I go and try to edit a row to change or add values for another field within the MRVS, I cannot view any of the data added via the Script Include. 
I have attached all code and screenshots to show what is happening. Any help would be appreciated.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var studentID = g_form.getValue("student_id");
    if (newValue == 'Yes') {
        var confirmBox = confirm("Please confirm that you want to add Student Homeroom values to the Close Contacts List");

        if (confirmBox == true) {
            var ga = new GlideAjax('global.GetHomeroomVals2');
            ga.addParam('sysparm_name', 'populateMRVS');
            ga.addParam('sysparm_ID', studentID);
            ga.getXML(returnMRVS);
	}
		else if (confirmBox == false){
			g_form.setValue('pop_homeroom_vals', 'No');
		}
            function returnMRVS(response) {
                var answer = response.responseXML.documentElement.getAttribute("answer");
                g_form.setValue('close_contact_list', answer);
        }
        //Type appropriate comment here, and begin script below
    }
}
var GetHomeroomVals2 = Class.create();
GetHomeroomVals2.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    populateMRVS: function() {

        var mrvsArray = []; //array to push values
        var studentIDServer = this.getParameter("sysparm_ID"); //bring in Student ID from Record Producer
        var grStudentDetailsID = new GlideRecord('student_account'); //GlideRecord on Student Account table
        grStudentDetailsID.addQuery('u_student_id', studentIDServer); 
        grStudentDetailsID.query();

        while (grStudentDetailsID.next()) {
            //query values on Student Account table where students share same homeroom as student with ID inputted on Record Producer
            var studentHomeroom = grStudentDetailsID.getValue('u_homeroom');
            var studID = grStudentDetailsID.getValue('u_student_id');

            //Query Student Details table to get Primary Learning Facility
            var grStudentFacility = new GlideRecord('student_account_detail');
            grStudentFacility.addQuery('u_student_id.u_student_id', studID);
            grStudentFacility.query();
            if (grStudentFacility.next()) {
                var facility = grStudentFacility.u_primary_learning_facility.toString();
            }
            //query records with matching Homeroom and Primary Learning Facility
            var grStudentDetailsHomeroom = new GlideRecord('student_account_detail');
            grStudentDetailsHomeroom.addQuery('u_homeroom', studentHomeroom);
            grStudentDetailsHomeroom.addQuery('u_primary_learning_facility', facility);

            grStudentDetailsHomeroom.addQuery('u_student_id.u_student_id', "!=", studentIDServer);
            grStudentDetailsHomeroom.query();
            while (grStudentDetailsHomeroom.next()) {
                var studentPrimaryLearningFacility = grStudentDetailsHomeroom.getValue('u_primary_learning_facility');
                var dateOfBirth = grStudentDetailsHomeroom.u_date_of_birth.toString(); //get DOB of matched student
                var email = grStudentDetailsHomeroom.u_email.toString(); //get email value of matched student

                var grStudentDetailsHomeroomName = new GlideRecord('student_account');
                grStudentDetailsHomeroomName.get(grStudentDetailsHomeroom.getValue("u_student_id"));
                var studentName = grStudentDetailsHomeroomName.name.toString();
		var studentID2 = grStudentDetailsHomeroomName.u_student_id.toString(); //get Student ID of matched student to later query Student Contacts table for phone number of guardian/parent

                var grPhone = new GlideRecord('contacts_student_accounts');
                grPhone.addQuery("u_student_account.name", studentName);
                grPhone.query();
                while (grPhone.next()) {
                    var phone = grPhone.u_contact.mobile_phone.toString(); //get guardian or parent's phone number
                }
               //push queried values into array
                mrvsArray.push({
                    "date_close_contact": "",
                    "student": '',
                    "date_of_birth": dateOfBirth,
                    "staff_user": "",
                    "name": studentName,
                    "pregnant_immuno": "Unknown",
                    "phone_number": phone,
                    "relationship_case": "classmate",
                    "email": email
                });
            }
            var mrvsObj = JSON.stringify(mrvsArray);
        }
        return mrvsObj;
    },
    type: 'GetHomeroomVals2'
});

MRVS definition.PNGMRVS_edit.PNGMRVS_table.PNG

2 ACCEPTED SOLUTIONS

Sainath N
Mega Sage
Mega Sage

@Umar Nasir : Could you check if any of the catalog client scripts or catalog UI policy actions associated with the multi-row variable sets are causing the issue? as UI policies execute on load. For a test, could you deactivate them once and test or check in that direction?

 

As per the screenshots, you shared, I see 2 client scripts and 3 catalog UI policies.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

View solution in original post

Hi Sainath, thank you for reaching out towards a solution.

I looked at the problem over the weekend and found that two of the MRVS Client Scripts were in-fact the culprits for clearing the row values on the Record Producer form.

 

Within the isLoading block, the fields were being cleared, so I commented those lines out. Everything is good now. I guess this is a reminder to check all Client Scripts even if they are onChange ones for variables that have nothing to do with the ones you are working on.

Thanks for your input!

View solution in original post

2 REPLIES 2

Sainath N
Mega Sage
Mega Sage

@Umar Nasir : Could you check if any of the catalog client scripts or catalog UI policy actions associated with the multi-row variable sets are causing the issue? as UI policies execute on load. For a test, could you deactivate them once and test or check in that direction?

 

As per the screenshots, you shared, I see 2 client scripts and 3 catalog UI policies.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Hi Sainath, thank you for reaching out towards a solution.

I looked at the problem over the weekend and found that two of the MRVS Client Scripts were in-fact the culprits for clearing the row values on the Record Producer form.

 

Within the isLoading block, the fields were being cleared, so I commented those lines out. Everything is good now. I guess this is a reminder to check all Client Scripts even if they are onChange ones for variables that have nothing to do with the ones you are working on.

Thanks for your input!