How to remove dependent values if parent value cleared from list collector fields?

venkat Y
Tera Contributor

find_real_file.png

I wrote Script include and called this in Reference qualifier of Leve2, Level3 fields.

I have used Ppm reference choice table to give parent values for Leve2, and Level3  Values.

while I removing Values after selection from Level1, Level2, Level3, those values only removing itself.

But not removing dependencies. 

If I removed "Hire to Retire", the dependencies Payroll and "Perform customer Risk Analysis" should clear.

I have given Parent values in "Ppm reference choice table"

I will be Thankful to you for your help and patience.

var BusinessProcessLevel = Class.create();

BusinessProcessLevel.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    ProcessLevel1Values: function(processLevel1) {
        var arrchoices1 = [];
        var choices1 = new GlideRecord('u_ppm_reference_choices');
        choices1.addEncodedQuery('u_parent.sys_idIN' + processLevel1);
        choices1.addEncodedQuery('u_active=true');
        choices1.query();
        while (choices1.next()) {
            arrchoices1.push(choices1.getUniqueValue());
        }
        return "sys_idIN" + arrchoices1.join(",");
    },

    ProcessLevel2Values: function(processLevel2) {
        var arrchoices2 = [];
        var choices2 = new GlideRecord('u_ppm_reference_choices');
        choices2.addEncodedQuery('u_parent.sys_idIN' + processLevel2);
        choices2.addEncodedQuery('u_active=true');
        choices2.query();
        while (choices2.next()) {
            arrchoices2.push(choices2.getUniqueValue());
        }
        return "sys_idIN" + arrchoices2.join(",");
    },
    type: 'BusinessProcessLevel'
});

u_business_process_level_2 field Reference Qualifier:

javascript:if(current.getValue("u_business_process_level_1"))new BusinessProcessLevel().ProcessLevel1Values(current.getValue("u_business_process_level_1"));

u_business_process_level_3 field Reference Qualifier:

javascript:if(current.getValue("u_business_process_level_2"))new BusinessProcessLevel().ProcessLevel2Values(current.getValue("u_business_process_level_2"));

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hello Venkat,

The reference qualifier will not clear the values selected on the fields. The reference qualifier will show the required values when someone clicks on magnify glass icon on reference field or when someone search the value in reference field.

To remove the values from these list collector field you need to write onChange client script on Level1 and Level2 fields as shown below:

Level1 field Client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.clearValue('u_business_process_level_2');
        return;
    }
    var processLevel2 = g_form.getValue("u_business_process_level_2").toString();
    if (newValue && processLevel2) {
        var getAvaCnt = new GlideAjax('BusinessProcessLevel');
        getAvaCnt.addParam('sysparm_name', 'getProcessLevel2Values');
        getAvaCnt.addParam('sysparm_process_level1', newValue);
	getAvaCnt.addParam('sysparm_process_level2', processLevel2);
        getAvaCnt.getXMLAnswer(parseReceivedData);
    } else {
        g_form.clearValue('u_business_process_level_2');
    }
	function parseReceivedData(response) {
		var answer = response.split(",");
		if (answer.length) {
			g_form.setValue("u_business_process_level_2", answer.join(","));
		}
	}
}

Level2 Client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.clearValue('u_business_process_level_3');
        return;
    }
    var processLevel3 = g_form.getValue("u_business_process_level_3").toString();
    if (newValue && processLevel3) {
        var getAvaCnt = new GlideAjax('BusinessProcessLevel');
        getAvaCnt.addParam('sysparm_name', 'getProcessLevel3Values');
        getAvaCnt.addParam('sysparm_process_level2', newValue.toString());
	getAvaCnt.addParam('sysparm_process_level3', processLevel3);
        getAvaCnt.getXMLAnswer(parseReceivedData);
    } else {
        g_form.clearValue('u_business_process_level_3');
    }
	function parseReceivedData(response) {
		var answer = response.split(",");
		if (answer.length) {
			g_form.setValue("u_business_process_level_3", answer.join(","));
		}
	}
}

Updated Script include: Client Callable should be checked on your Script include 

var BusinessProcessLevel = Class.create();

BusinessProcessLevel.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getProcessLevel2Values: function () {
		var level2Process = [];
		var processLevel1 = this.getParameter("sysparm_process_level1");
		var processLevel2 = this.getParameter("sysparm_process_level2");
		var choices1 = new GlideRecord('u_ppm_reference_choices');
        choices1.addEncodedQuery('u_active=true^u_parent.sys_idIN' + processLevel1 + "^sys_idIN" + processLevel2);
        choices1.query();
        while (choices1.next()) {
            level2Process.push(choices1.getUniqueValue());
        }
		return level2Process.join(",");
	},
	
	getProcessLevel3Values: function () {
		var level3Process = [];
		var processLevel2 = this.getParameter("sysparm_process_level2");
		var processLevel3 = this.getParameter("sysparm_process_level3");
		var choices1 = new GlideRecord('u_ppm_reference_choices');
        choices1.addEncodedQuery('u_active=true^u_parent.sys_idIN' + processLevel2 + "^sys_idIN" + processLevel3);
        choices1.query();
        while (choices1.next()) {
            level3Process.push(choices1.getUniqueValue());
        }
		return level3Process.join(",");
	},

    ProcessLevel1Values: function(processLevel1) {
        var arrchoices1 = [];
        var choices1 = new GlideRecord('u_ppm_reference_choices');
        choices1.addEncodedQuery('u_parent.sys_idIN' + processLevel1);
        choices1.addEncodedQuery('u_active=true');
        choices1.query();
        while (choices1.next()) {
            arrchoices1.push(choices1.getUniqueValue());
        }
        return "sys_idIN" + arrchoices1.join(",");
    },

    ProcessLevel2Values: function(processLevel2) {
        var arrchoices2 = [];
        var choices2 = new GlideRecord('u_ppm_reference_choices');
        choices2.addEncodedQuery('u_parent.sys_idIN' + processLevel2);
        choices2.addEncodedQuery('u_active=true');
        choices2.query();
        while (choices2.next()) {
            arrchoices2.push(choices2.getUniqueValue());
        }
        return "sys_idIN" + arrchoices2.join(",");
    },
    type: 'BusinessProcessLevel'
});

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

View solution in original post

7 REPLIES 7

Wowwwww...Wonderfulllll...Mahendra...shabashhhh...!

finally its working... 

Big thanks...brother..

I would appreciate Your patience first... Thanks for the code.

Hi Mahendra,

On new Demand form creation, after updating the values. after saving the form not showing Level2 and Level3 values which I had entered. Please help me on this.find_real_file.png

venkat Y
Tera Contributor

Wowwwww...Wonderfulllll...Mahendra...shabashhhh...!

finally its working... 

Big thanks...brother, If you are infront of me I will give heartfully Hug...

I would appreciate Your patience first... Thanks for the code.