User should be restricted form access if he/she click on Decline - OnLoad Script

Ankita9793
Tera Contributor

 

Hi All,

 

User should be restricted form access if he/she click on Decline, How can i do that?

Please suggest, TIA

 

Ankita9793_1-1759134163296.png

 

 

function onLoad() {

        spModal.open({
            title: getMessage('Information'),
            message: getMessage('Please make sure you have completed pre-requisites before raising engagement request with email team. SLA --> 15 business days after completion of cyber review approval. Do you want to proceed?'),
            buttons: [{
                    label: 'Decline',
                    cancel: true
                },
                {
                    label: 'Proceed',
                    primary: true
                }],
        });

        return false;
    }


    g_form.setFieldStatus('alternate_number', false, false);
 
 
Ankita9793_0-1759134156029.png

 

1 ACCEPTED SOLUTION

M Iftikhar
Mega Sage

Hi @Ankita9793 ,

You can handle this in your onLoad() function by adding an action to the Decline button:

function onLoad() {
    spModal.open({
        title: getMessage('Information'),
        message: getMessage('Please make sure you have completed pre-requisites before raising engagement request with email team. SLA --> 15 business days after completion of cyber review approval. Do you want to proceed?'),
        buttons: [
            {
                label: 'Decline',
                cancel: true,
                action: function() {
                    // Option 1: Redirect to Service Portal home
                    window.location.href = '/sp'; 
                }
            },
            {
                label: 'Proceed',
                primary: true,
                action: function() {
                    // Allow user to continue
                }
            }
        ]
    });
}

For Decline, you can either:

  • Redirect to Service Portal home → window.location.href = '/sp';

  • Redirect to logout → window.location.href = '/logout.do';

  • Make the form read-only → g_form.setReadOnly(true);


Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.

View solution in original post

2 REPLIES 2

M Iftikhar
Mega Sage

Hi @Ankita9793 ,

You can handle this in your onLoad() function by adding an action to the Decline button:

function onLoad() {
    spModal.open({
        title: getMessage('Information'),
        message: getMessage('Please make sure you have completed pre-requisites before raising engagement request with email team. SLA --> 15 business days after completion of cyber review approval. Do you want to proceed?'),
        buttons: [
            {
                label: 'Decline',
                cancel: true,
                action: function() {
                    // Option 1: Redirect to Service Portal home
                    window.location.href = '/sp'; 
                }
            },
            {
                label: 'Proceed',
                primary: true,
                action: function() {
                    // Allow user to continue
                }
            }
        ]
    });
}

For Decline, you can either:

  • Redirect to Service Portal home → window.location.href = '/sp';

  • Redirect to logout → window.location.href = '/logout.do';

  • Make the form read-only → g_form.setReadOnly(true);


Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita9793 

sorry didn't get your requirement?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader