Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

miftikhar20
Kilo Patron

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.

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

3 REPLIES 3

FasihaM
Tera Contributor

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() {
                    // Redirect to home page (or any other page)
                    window.location.href = '/sp'; 
                }
            },
            {
                label: 'Proceed',
                primary: true,
                action: function() {
                    // User can continue using the form
                }
            }
        ]
    });
}

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

miftikhar20
Kilo Patron

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.

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

@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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader