A selectBox variable is not autopopulating

Dave_p
Giga Guru

Hi,

 

I am autopopulating multiple variables of which one SelectBox is not autopopulating. Kindly help.

 

GlideAJAX

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue == "") {
        g_form.setValue('current_primary_approver', "");
        g_form.setValue('share_type', "");
        g_form.setValue('protocol_type', "");
    } else {
        var ga = new GlideAjax('populate_modify_network');
        ga.addParam('sysparm_name', 'get_modify');
        ga.addParam('sysparm_share_path', newValue);
        ga.getXML(callBackFunction);
        function callBackFunction(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            var op = JSON.parse(answer);
            g_form.setValue('current_primary_approver', op.approver);
            g_form.setValue('share_type', op.type);
            g_form.setValue('protocol_type', op.protocol);
        }

    }
}

 

1.png

 

ScriptIncludes

 

var populate_modify_network = Class.create();
populate_modify_network.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	get_modify : function()
	{
		var path = this.getParameter('sysparm_share_path');
		var values = {};
		
		var gr = new GlideRecord('u_cmdb_ci_file_share');
		gr.addQuery('sys_id',path);
		gr.query();
		if(gr.next())
			{
				values.approver = gr.managed_by.toString();
				values.type = gr.u_type.getDisplayValue();
				values.protocol = gr.u_protocol.getDisplayValue();			
			}
		return JSON.stringify(values);
	},

    type: 'populate_modify_network'
});

 

2.png

 

3.png

 

5.png

 

6.png

 

You can see Share Type populating but not Protocol Type. Both are SelectBox variables.

 

Regards

Suman P.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Dave_p 

what came in the JSON? is the JSON coming fine?

I could see the variable is drop down type. I hope the choices for that drop down variable and the choices for field u_protocol are same.

If yes then update this line so that you get choice value and not choice label

				values.protocol = gr.u_protocol.toString();			

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Dave_p 

what came in the JSON? is the JSON coming fine?

I could see the variable is drop down type. I hope the choices for that drop down variable and the choices for field u_protocol are same.

If yes then update this line so that you get choice value and not choice label

				values.protocol = gr.u_protocol.toString();			

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Dave_p 

ideally no scripting required if you use auto populate feature

It basically means you are making other 2 variables dependent on your reference variable

Auto-populate a variable based on a reference type variable (Utah) 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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