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

Script Include Question

Community Alums
Not applicable

Hi,

I have return a GlideAJAX and ScriptInclude but I am getting [Object Object]. Both the variables are DropDown variables (Protocol and Type) in the main table (u_cmdb_ci_file_share). Kindly help. 

 

GlideAJAX

GlideAJAX.png

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }


	var ga = new GlideAjax('ModifyNetworkSharePathClass');
	ga.addParam('sysparm_name', 'ModifyNetworkSharePathFunction');
	ga.addParam('passVariable', newValue);
	ga.getXML(callBackFunction);
	function callBackFunction(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
		var op = JSON.parse(answer);
		g_form.setValue('share_type', op.sharetype);
		g_form.setValue('protocol_type', op.protocoltype);
	}


}

 

ScriptInclude

ScriptInclude.png

 

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

	ModifyNetworkSharePathFunction: function(){

		var valuesShare = this.getParameter('passVariable');
		var gr = new GlideRecord('u_cmdb_ci_file_share');
		gr.addQuery('sys_id', valuesShare);
		gr.query();
		if(gr.next()){
			var jsonOBJ = {};
			jsonOBJ.sharetype = gr.u_type;
			jsonOBJ.protocoltype = gr.u_protocol;
			var json = new JSON().encode(jsonOBJ);
			return json;
		}

	},

    type: 'ModifyNetworkSharePathClass'
});

 

output.png

 

type.pngprotocol.png

 

Regards

Suman P

 

1 ACCEPTED SOLUTION

Change it from getValue to getDisplayValue

 

Regards,

Sumanth

View solution in original post

8 REPLIES 8

Try debugging by logging the values of stringified object in script include.

Expected it should print Json as a string. If not then some issue in script include itself while constructing JSON object.

If still you are not able to find the issue then instead of JSON you can simply pass as a comma separated string and try.

 

Regards,

Sumanth

Simon Christens
Kilo Sage

Hi,

In your script include, try:

if (gr.next()) {
            var jsonOBJ = {};
            jsonOBJ.sharetype = gr.getValue('u_type');
            jsonOBJ.protocoltype = gr.getValue('u_protocol');
          
            return JSON.stringify(jsonOBJ);
        }

getValue always return a string value.

gr.field is a gliderecord object - you cant expect a string to be returned just by dot.walk the field

Community Alums
Not applicable

Hi @Simon Christens,

 

I am getting the proper value by changing this. However, there is an issue. I am getting sys_id for the reference variable. Kindly help.

 

 

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

    ModifyNetworkSharePathFunction: function() {

        var valuesShare = this.getParameter('passVariable');
		var jsonOBJ = {};
        var gr = new GlideRecord('u_cmdb_ci_file_share');
        gr.addQuery('sys_id', valuesShare);
        gr.query();
        if (gr.next()) {
            
            jsonOBJ.sharetype = gr.u_type.getDisplayValue();
            jsonOBJ.protocoltype = gr.u_protocol.getDisplayValue();
			jsonOBJ.approver = gr.managed_by.toString();
          //  var json = new JSON().encode(jsonOBJ);
            return JSON.stringify(jsonOBJ);
        }

    },

    type: 'ModifyNetworkSharePathClass'
});

 

 

approver.png

Change it from getValue to getDisplayValue

 

Regards,

Sumanth