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

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);
...

payalpatel26
Tera Contributor

Thanks 😀😀 its work on Script Include but not generate popup on client side please help if you find something 

 

 

 

My Client Script :

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
 
    //Type appropriate comment here, and begin script below
 
 
   var selectedType = g_form.getValue('type');
 
    g_form.addInfoMessage("selectedValueInClient" + selectedType);
 
    // Fetch Questions based on the selected Type using GlideAjax
    getQuestionsBasedOnType( g_form.getValue('type'), function(questions) {
 
        // Check if the response has an error
        if (questions && response.responseXML && response.responseXML.documentElement) {
            var errorMessage = response.responseXML.documentElement.getAttribute('error');
            if (errorMessage) {
                g_form.addInfoMessage('GlideAjax Error:', errorMessage);
            }
        }
 
        // Create and show the popup
        var dialog = new GlideDialogWindow('ServiceRequestGuidance');
        dialog.setTitle("Legal Service Matters Detail");
        dialog.setWidth(600);
        dialog.setHeight(400);
 
        var html = "<div>";
        for (var i = 0; i < questions.length; i++) {
            var question = questions[i];
            html += "<label>" + question + "</label>";
            html += '<input type="text" id="question_' + i + '"/><br>';
        }
        html += '</div>';
 
        dialog.renderWithContent(html);
 
        dialog.setPreference('selectedType', selectedType);
        dialog.setPreference('numOfQuestions', questions.length);
        dialog.setPreference('table', g_form.getTableName());
        dialog.setPreference('recordSysId', g_form.getUniqueValue());
 
        dialog.show();
    });
 
}
 
function getQuestionsBasedOnType(selectedType, callback) {
g_form.addInfoMessage('checkSelecteryTypeScrptFunc:' +  selectedType);
    var ga = new GlideAjax('FetchPromptStrctureBasedOnChangeServiceType');
    ga.addParam('sysparm_name', 'getQuestionsBasedOnType');
    ga.addParam('sysparm_selectedType', selectedType);
    ga.getXML(function(response) {
 
        if (response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            if (answer) {
                var questions = answer.split(',');
                callback(questions);
            } else {
                alert("Empty or invalid 'answer' attribute in the response from the server.");
 
            }
        } else {
            alert("Empty or invalid response received from the server.");
        }
    });
}
 
 
second question if we dont pass sysid instead of pass string value then what we have to do

The client script has several problems:

- it is GlideModal (NOT GlideDialogWindow) that supports renderWithContent()

- neither GlideDialogWindow or GlideModal has a method called show()

- even if they did, the dialog is already displayed when calling method renderWithContent() - assuming the code is updated to use GlideModal

- that means that everything that comes after renderWithContent() has no use

- depending on use case, the proper solution might be not a Script Include and GlideAjax, but a UI Page.

 

So before going forward, what is the business requirement (or experiment requirements) that you are trying to fulfill here?

payalpatel26
Tera Contributor

My requirement when user select the type that time generate the pop which show value of prompt structure 

payalpatel26
Tera Contributor

As i check in my instance i dont have GlideModal only have  GlideDialogWindow.

can  you tell me how to render html in GlideDialogWindow ?

 i cant  get g_form.getUniqueValue so Could provvide me reason why?