Not render Content In GlideDialogWindow

payalpatel26
Tera Contributor

Clinet Sript :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) {

// Create and show the popup
var dialog = new GlideDialogWindow('ServiceRequestGuidance');
dialog.setTitle("Legal Service Matters Detail");
dialog.render();
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', "x_1296451_legaladv_servicetype");
dialog.setPreference('recordSysId', g_form.getUniqueValue());
dialog.render();
});

}

function getQuestionsBasedOnType(selectedType, callback) {

var ga = new GlideAjax('FetchPromptStrctureBasedOnChangeServiceType');
ga.addParam('sysparm_name', 'getQuestionsBasedOnType');
ga.addParam('sysparm_selectedType', selectedType);
ga.getXML(function(response) {

g_form.addInfoMessage('responseInClientSide:' + response.responseXML.documentElement.getAttribute("answer"));
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.");
}
});
}

 

==========================================================

I got the response from Script Include but Dialog box not properly render 

 

payalpatel26_0-1704743999100.png

payalpatel26_1-1704743999231.png

 

2 REPLIES 2

Maik Skoddow
Tera Patron
Tera Patron

Hi @payalpatel26 

your code makes no sense.

On the one hand you want to load an UI Page "ServiceRequestGuidance" via 

var dialog = new GlideDialogWindow('ServiceRequestGuidance');

 

And on the other hand, you create custom HTML code for displaying within the modal via

dialog.renderWithContent(html);

 

You cannot do both approaches in parallel! Decide to either load an UI Page or render custom HTML.

 

Maik

I am beginner for service now so i thought  its title . now i created ui page which look like

 

payalpatel26_0-1704829369399.png

This my client script i got null in  web page where  i  want to show question ?

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);
g_form.addInfoMessage("Checkniuwvalue",g_form.getUniqueValue());
g_form.addInfoMessage("ChecktableName",g_form.getTableName());
 
 
    // Fetch Questions based on the selected Type using GlideAjax
    getQuestionsBasedOnType( g_form.getValue('type'), function(questions) {
 
         // Create and show the popup
        var dialog = new GlideDialogWindow('DisplayPromptStrctureWindow');
        
 
        dialog.setWidth(600);
        dialog.setHeight(400);
dialog.setPreference('numOfQuestions', questions);
         dialog.render();
    });
 
}
 
function getQuestionsBasedOnType(selectedType, callback) {
 
    var ga = new GlideAjax('FetchPromptStrctureBasedOnChangeServiceType');
    ga.addParam('sysparm_name', 'getQuestionsBasedOnType');
    ga.addParam('sysparm_selectedType', selectedType);
    ga.getXML(function(response) {
 
g_form.addInfoMessage('responseInClientSide:' +  response.responseXML.documentElement.getAttribute("answer"));
        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.");
        }
    });
}