Display External Website in iFrame for Catalog Item in ServiceNow

AgimB
Tera Contributor

I’ve created a catalog item in ServiceNow where, when an end user attaches a file, a catalog script is triggered that opens a modal with an external website (in an iframe). However, I keep encountering a "Page Not Found" error.

Here’s what I’ve done so far:

  • Created a catalog script that triggers on attachment.
  • Used a modal to display the URL.

But for some reason, the page doesn’t load correctly and shows "The page you are looking for could not be found."
Here is the script I am using:

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
    // Check if the form is still loading or if the field is empty
    if (isLoading || newValue === '') {
        return; // Do nothing if the form is still loading or no file is attached
    }
    alert("I have been called");
    // Create the modal with the specified URL once the document is added
    var iframeUrl = 'https://www.example.com/';
    
    var dialog = new GlideModal("custom_dialog");
    dialog.setTitle("Document Added Successfully");
    dialog.setBody("<iframe src='" + iframeUrl + "' style='width:100%; height:400px;'></iframe>");
    dialog.render();  // Show the modal
}

 

 

 

What I’ve Tried:

  • Checked the URL for typos.
  • Looked into iframe restrictions, such as the X-Frame-Options header for the external website that part is good. I belive the restriction is in ServiceNow side.
  • I have already looked into the glide.set_x_frame_options property set it to false, and it doesn't solve the issue.
1 ACCEPTED SOLUTION

Dennis Braun
Tera Expert

I think you have to call the modal as follows - then the iframe will be displayed correctly:

    var iframeUrl = 'https://www.example.com/';
    var htmlData = ("<iframe src='" + iframeUrl + "' style='width:100%; height:400px;'></iframe>");
    var dialog = new GlideModal("custom_dialog");
    dialog.setTitle("Document Added Successfully");
    dialog.renderWithContent(htmlData);

DennisBraun_0-1726119822216.png

 

View solution in original post

2 REPLIES 2

Dennis Braun
Tera Expert

I think you have to call the modal as follows - then the iframe will be displayed correctly:

    var iframeUrl = 'https://www.example.com/';
    var htmlData = ("<iframe src='" + iframeUrl + "' style='width:100%; height:400px;'></iframe>");
    var dialog = new GlideModal("custom_dialog");
    dialog.setTitle("Document Added Successfully");
    dialog.renderWithContent(htmlData);

DennisBraun_0-1726119822216.png

 

Thank you @Dennis Braun it worked.