Not Get response From Server Side Script Include

payalpatel26
Tera Contributor
var FetchPromptStrctureBasedOnChangeServiceType = Class.create();
FetchPromptStrctureBasedOnChangeServiceType.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    // Function to fetch questions based on the selected type
    getQuestionsBasedOnType: function (selectedType) {
        var selectedType = this.getParameter('sysparm_selectedType');
gs.addInfoMessage("serverSideType"+selectedType);
 
        // Query the 'ServiceType' table and retrieve questions
        var serviceTypeGR = new GlideRecord('ServiceType');
serviceTypeGR.addQuery('type', selectedType);
serviceTypeGR.query();
 
        if (serviceTypeGR.next()) {
            var promptStructure = serviceTypeGR.getValue('promptstructure');
            return promptStructure ; // Return an empty string if PromptStructure is null
        }
 
      
    },
 
    type: 'FetchPromptStrctureBasedOnChangeServiceType'
});

 

1 ACCEPTED SOLUTION

Please also take a screenshot of the other field - promptstructure.

 

But even from this screenshot a problem can be seen: type is of type String in which you are looking for a sys_id.

That is theoretically possible but very NOT likely.

So the problem could be line

serviceTypeGR.addQuery('type', selectedType);

in the Script Include.

It is possible and likely that what you mean is:

serviceTypeGR.addQuery('sys_id', selectedType);

which can be short-handed to:

...
// Query the 'ServiceType' table and retrieve questions
var serviceTypeGR = new GlideRecord('x_1296451_legaladv_servicetype');

if (serviceTypeGR.get(selectedType)) {
	gs.addInfoMessage('serviceoog' + serviceTypeGR);
	promptStructure = serviceTypeGR.getValue('promptstructure');
}

gs.addInfoMessage('promptStructure ' + promptStructure);
...

View solution in original post

22 REPLIES 22

Sagar Pagar
Tera Patron

Hello @payalpatel26,

 

Try this updated scripts -

var FetchPromptStrctureBasedOnChangeServiceType = Class.create();
FetchPromptStrctureBasedOnChangeServiceType.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	// Function to fetch questions based on the selected type

	getQuestionsBasedOnType: function() {

		var promptStructure;
		var selectedType = this.getParameter('sysparm_selectedType');
		
		gs.addInfoMessage("serverSideType" + selectedType);

		// Query the 'ServiceType' table and retrieve questions
		var serviceTypeGR = new GlideRecord('ServiceType');
		serviceTypeGR.addQuery('type', selectedType);
		serviceTypeGR.query();
		if (serviceTypeGR.next()) {
			promptStructure = serviceTypeGR.getValue('promptstructure');
		}
		return promptStructure; // Return an empty string if PromptStructure is null
	},

	type: 'FetchPromptStrctureBasedOnChangeServiceType'
});

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Thanks But Still Got null 

 

payalpatel26_2-1704570711573.png

 

Are you sure the table name serviceType is correct? If it is a custom table, table name could be u_servicetype and field name could be u_type/


Please mark this response as correct or helpful if it assisted you with your question.

I create a private scope application so when we create a table name one is lable that we give name second name define by the system so are you talking about sys define table