<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Help with onLoad modal in catalog client script in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501079#M1249432</link>
    <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/272236"&gt;@Biddaum&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then try this and it will work in portal&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;function onLoad() {
    var modalInstance;

    spModal.open({
        title: 'This is a test',
        message: 'Please select cancel if you want to go back',
        buttons: [{
            label: 'Proceed',
            value: 'agree',
            primary: true // Makes this button visually prominent
        }, {
            label: 'Cancel',
            value: 'disagree'
        }]
    }).then(function(result) {
        // This function executes when a button is clicked
        if (!result.primary) {
            top.location.href = 'https://www.testing.com';
        } else {
            if (modalInstance) {
                modalInstance.dismiss(); // Dismisses the modal
            }
        }
    });
}&lt;/LI-CODE&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":light_bulb:"&gt;💡&lt;/span&gt; If my response helped, please mark it as correct &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; and close the thread &lt;span class="lia-unicode-emoji" title=":locked:"&gt;🔒&lt;/span&gt;— this helps future readers find the solution faster! &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Mar 2026 04:08:18 GMT</pubDate>
    <dc:creator>Ankur Bawiskar</dc:creator>
    <dc:date>2026-03-04T04:08:18Z</dc:date>
    <item>
      <title>Help with onLoad modal in catalog client script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3500982#M1249417</link>
      <description>&lt;P&gt;I have a requirement to have a modal on load to present a message to the requester when they load a catalog item.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most times they are likely going to select the positive option and want to proceed, however I need to cover the chance that they don't want to proceed. So I want to take them back to either their previous page or to a set url if they cancel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are on Zurich and this is on Employee Centre&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is what I currently have in a catalog client script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Applies to - A Catalog Item&lt;/P&gt;&lt;P&gt;Active is true&lt;/P&gt;&lt;P&gt;UI Type - ALL&lt;/P&gt;&lt;P&gt;Type - onLoad&lt;/P&gt;&lt;P&gt;Applies on Catalog Item view - True&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onLoad() {
    //Type appropriate comment here, and begin script below

    if (typeof spModal !== 'undefined') {

        if (g_scratchpad.isFormValid) {
            return true;
        }

        var actionName = g_form.getActionName();

        spModal.open({
            backdrop: 'static',
            keyboard: false,
            message: 'Please select cancel if you want to go back',
            title: 'This is a test',
            buttons: [{
                    label: 'Cancel',
                    cancel: true
                },
                {
                    label: 'Proceed',
                    primary: true
                }
            ]
        }).then(
            function onAgree(result) {
                g_scratchpad.isFormValid = true;
                g_form.submit(actionName);
                return true;
            },
            function onDisagree(reason) {
                setTimeout(function() {
                    window.location.href = 'https://www.testing.com';
                }, 0);
                return false;
            }
        );

        g_scratchpad.isFormValid = false;
        return false;

    } else {
        var gm = new GlideModal();
        gm.setTitle('Error');
        gm.renderWithContent('Something has gone wrong Prompt');
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would love some help please.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2026 22:03:04 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3500982#M1249417</guid>
      <dc:creator>Biddaum</dc:creator>
      <dc:date>2026-03-03T22:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Help with onLoad modal in catalog client script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501063#M1249428</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/272236"&gt;@Biddaum&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so your requirement is simply to show modal and 2 buttons&lt;/P&gt;
&lt;P&gt;Proceed and Cancel&lt;/P&gt;
&lt;P&gt;On click of Cancel take them to portal home?&lt;/P&gt;
&lt;P&gt;On click of Proceed close the modal and let them submit form?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 03:36:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501063#M1249428</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2026-03-04T03:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help with onLoad modal in catalog client script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501070#M1249429</link>
      <description>&lt;P&gt;You have to set isolate script to false, then you can access the window object from this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onLoad() {
    //Type appropriate comment here, and begin script below

    if (typeof spModal !== 'undefined') {

        if (g_scratchpad.isFormValid) {
            return true;
        }

        var actionName = g_form.getActionName();

        spModal.open({
            backdrop: 'static',
            keyboard: false,
            message: 'Please select cancel if you want to go back',
            title: 'This is a test',
            buttons: [{
                    label: 'Cancel',
                    cancel: true
                },
                {
                    label: 'Proceed',
                    primary: true
                }
            ]
        }).then(
            function onAgree(result) {
                g_scratchpad.isFormValid = true;
                g_form.submit();
                return true;
            },
            function onDisagree(reason) {
                setTimeout(function() {
                    this.location.href = 'https://www.testing.com';
                }, 0);
                return false;
            }
        );

        g_scratchpad.isFormValid = false;
        return false;

    } else {
        var gm = new GlideModal();
        gm.setTitle('Error');
        gm.renderWithContent('Something has gone wrong Prompt');
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;To successfully submit with gform on the catalog item widget you also need to do something like this. Make sure you dont have two step checkout on the item&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const $scope = angular.element("#sc_cat_item").scope()
$scope.data.sc_cat_item.item_action = "order";
g_form.submit()
//or maybe instead of submit use
$scope.triggerOnSubmit()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 03:45:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501070#M1249429</guid>
      <dc:creator>lauri457</dc:creator>
      <dc:date>2026-03-04T03:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help with onLoad modal in catalog client script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501075#M1249430</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;yes that is correct&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 03:58:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501075#M1249430</guid>
      <dc:creator>Biddaum</dc:creator>
      <dc:date>2026-03-04T03:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help with onLoad modal in catalog client script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501079#M1249432</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/272236"&gt;@Biddaum&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then try this and it will work in portal&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;function onLoad() {
    var modalInstance;

    spModal.open({
        title: 'This is a test',
        message: 'Please select cancel if you want to go back',
        buttons: [{
            label: 'Proceed',
            value: 'agree',
            primary: true // Makes this button visually prominent
        }, {
            label: 'Cancel',
            value: 'disagree'
        }]
    }).then(function(result) {
        // This function executes when a button is clicked
        if (!result.primary) {
            top.location.href = 'https://www.testing.com';
        } else {
            if (modalInstance) {
                modalInstance.dismiss(); // Dismisses the modal
            }
        }
    });
}&lt;/LI-CODE&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":light_bulb:"&gt;💡&lt;/span&gt; If my response helped, please mark it as correct &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; and close the thread &lt;span class="lia-unicode-emoji" title=":locked:"&gt;🔒&lt;/span&gt;— this helps future readers find the solution faster! &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 04:08:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501079#M1249432</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2026-03-04T04:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with onLoad modal in catalog client script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501080#M1249433</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;works perfectly thank you&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 04:12:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501080#M1249433</guid>
      <dc:creator>Biddaum</dc:creator>
      <dc:date>2026-03-04T04:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help with onLoad modal in catalog client script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501082#M1249434</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/384622"&gt;@lauri457&lt;/a&gt;&amp;nbsp; thank you for your help, I appreciate your reply&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could not however isolate the script as that option was no available on an onload script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We don't have two step checkout enabled at all&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 04:14:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501082#M1249434</guid>
      <dc:creator>Biddaum</dc:creator>
      <dc:date>2026-03-04T04:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help with onLoad modal in catalog client script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501107#M1249436</link>
      <description>&lt;P&gt;Isolate script can be used for all client scripts, but I didn't realise that it actually doesn't stop accessing top as shown in Ankurs solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The two step checkout would have mattered only if you needed the g_form.submit() call but it doesn't seem like you actually wanted that&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 05:00:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-onload-modal-in-catalog-client-script/m-p/3501107#M1249436</guid>
      <dc:creator>lauri457</dc:creator>
      <dc:date>2026-03-04T05:00:30Z</dc:date>
    </item>
  </channel>
</rss>

