Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

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

It looks like there is NO record in table x_1296451_legaladv_servicetype where field type has value 7f11...10b1.

Or the table name is not correct, or the field names (type and/or promptstructure) are not correct and thus the query/lookup is failing.

It would help if you could post a screenshot of the definition form of the table where the names (not labels!) of those fields is visible.

payalpatel26
Tera Contributor

Screen Shot prompt Structure

payalpatel26_0-1704671636885.png

 

That clears it, thanks.

Now a final question: where exactly (on which table) is this Client Script defined?

payalpatel26
Tera Contributor

Client Script defined on Service request table where i define reference field for service type 

payalpatel26
Tera Contributor

payalpatel26_0-1704669361137.png

 

list where record exist

 

 

payalpatel26_1-1704669422696.png