The CreatorCon Call for Content is officially open! Get started here.

SelectBox display value not displayed

Dave_p
Giga Guru

Hi,

 

I have two selectbox variables and one reference variable to autopopulate, but one selectbox is not displaying. 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_new', "");
    } else {
		alert(g_form.getValue('protocol_type_new'));
        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.addInfoMessage(answer);
            g_form.setValue('current_primary_approver', op.approver);
            g_form.setValue('share_type', op.type);
            g_form.setValue('protocol_type_new', op.protocol);
        }

    }
}

 

1.png

 

ScriptInclude

 

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

 

protocol.png3.pngESC.png

 

4.png

 

Even though Employment Center showing up as the correct protocol, it is not getting into the variable.

 

Regards

Suman P.

1 ACCEPTED SOLUTION

@Dave_p 

you should set either of those 2 choice values.

check the value in server side and set it accordingly

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();
            if (gr.u_protocol.toString() == 'Windows Only')
                values.protocol = 'windows';
            else
                values.protocol = 'multiprotocol';
        }
        return JSON.stringify(values);
    },

    type: 'populate_modify_network'
});

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

16 REPLIES 16

@Dave_p 

you should set either of those 2 choice values.

check the value in server side and set it accordingly

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();
            if (gr.u_protocol.toString() == 'Windows Only')
                values.protocol = 'windows';
            else
                values.protocol = 'multiprotocol';
        }
        return JSON.stringify(values);
    },

    type: 'populate_modify_network'
});

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

Hi @Ankur Bawiskar,

 

I made some progress but the variable is showing Multiprotocol no matter what i select.

 

Regards

Suman P.

@Dave_p 

did you add the if else check for the value?

share your updated script include code

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

You need to set the value of the variable to a Value that matches, so 'windows' in this case.  If you can without adversely affecting other things, change the Values of the variable choice records to match either the displayValues or values from the table, then use the appropriate method in the Script Include.

Dave_p
Giga Guru

Hi @Ankur Bawiskar ,

It is always going to else Ankur

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

    populate_modify_network_function: function() {
        var obj = this.getParameter('sysparm_share');
        var arrayss = {};
        var grec = new GlideRecord('u_cmdb_ci_file_share');
        grec.addQuery('sys_id', obj);
        grec.query();
        if (grec.next()) {
				arrayss.primary = grec.managed_by.toString();
				arrayss.shareType = grec.u_type.getDisplayValue();
				if (grec.u_protocol.toString() == 'Windows Only')
                arrayss.protocol_type = 'windows';
            else
                arrayss.protocol_type = 'multiprotocol';
        }
        
		return JSON.stringify(arrayss);
    },

    type: 'populate_modify_network_class'
});

 

Regards

Suman P.