Pop up message is not closing when "Acknowledge " button is clicked

CDJ
Tera Contributor

Hi All,

I’m trying to display the popup message with button and I’ve added a button "Acknowledge" inside the popup message to close it. However, when the button is clicked, the modal doesn’t close. I’ve defined the closeDialog() function and linked it to the button’s onclick event, but it doesn’t seem to work. Any ideas on why the button isn't closing the modal and how to fix it?

I'm getting this error -" onChange script error: TypeError: Cannot set properties of null (setting 'closeDialog') function () { [native code] }"

------------------------------------------------------------------------------

 

UI Page :

<html>

<head>

<title>AI System Acknowledgement</title>

</head>

<body>

<div id="popup-message">${sysparm_message}</div>

</body>

</html>

------------------------------------------------------------------------

 

Client Script : 

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue === oldValue) {

return;

}

if (newValue === 'yes') {

var dialog = new GlideModal('custom_ai_dialog', false); 

dialog.setTitle("AI System Acknowledgement");

var changeType = g_form.getValue('type');

var message = '';

if (changeType === 'standard') {

message =

"<b>This request includes a new AI system being introduced  and must be submitted as a Normal Change Request.</b><br><br>""As part of the review process, an approval from the group will be required before deployment.<br><br>""Please cancel this request and resubmit using a Normal Change Request.<br><br>""For additional information, please visit:<br>""<a href=' Test link' target='_blank'>Management</a><br><br>" +

 "or contact <a href='mailto:change@test.com'>change@test.com</a>";

}

else if (changeType === 'normal') {

message = "<b>You have indicated that this request includes a new AI system being introduced  .</b><br><br>" +

"Before submitting this Change Request, the Management questionnaire should be completed:<br>" +

"<a href='Test Link' target='_blank'>Model Risk Management</a><br><br>""Additionally, this change will require an extra approval step from the Test.<br><br>""Please ensure all required documentation has been submitted for review.<br><br>""If you have any questions, please reach out to <a href='mailto:test@test.com'>test@test.com</a>";

}

var fullMessage = message + "<br><br><button type='button' onclick='closeDialog()' class='btn btn-primary'>Acknowledge</button>";

        dialog.setBody(fullMessage);

        window.closeDialog = function() {

            dialog.destroy(); 

        };

dialog.render();

    }

}

#ServiceNow #JavaScript - Thanks in advance!

1 REPLY 1

CDJ
Tera Contributor

Hi @Ankur Bawiskar - Adding you in this communication. Could you please assist on this issue.