Onsubmit script is not working with script

is_12
Tera Contributor

Hello Community !

 

function onSubmit() {
    if (g_user.hasRole('sn_customerservice_agent')) {
        var ga = new GlideAjax('catalogUtils');
        ga.addParam('sysparm_name', 'hasExistingRITM');
        ga.addParam('sysparm_account', g_form.getValue('account'));
        ga.addParam('sysparm_userId', g_form.getValue('contact_name'));
        ga.addParam('sysparm_catalogItem', g_form.getUniqueValue());
        ga.getXMLAnswer(setData);

    }

    function setData(response) {
        var answer = response;
        alert('reponse' + answer);
        if (answer == 'false') {
            alert(getMessage('You are not allowed to order as there is an existing request for this customer'));
           return false;
        } else {
            alert("else if alert");
            return true;
        }
    }
}
I'm getting the alert message but form is getting submitted.
Tried with getXMLWait(), it is getting supported
 
Thanks,
2 ACCEPTED SOLUTIONS

@is_12 

this worked for me in onLoad catalog client script

I hope I answered your question and you can enhance it further.

function onLoad() {
		var element = this.document.getElementsByClassName('btn btn-primary btn-block text-overflow-ellipsis ng-binding ng-scope');
		element[0].style.display = 'none';
}

AnkurBawiskar_0-1747748977910.png

 

Output:

AnkurBawiskar_1-1747748998896.png

 

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

View solution in original post

23 REPLIES 23

is_12
Tera Contributor

@OlaN @Ankur Bawiskar after the alert message, agent should not be able to submit the form, if he click's as well it should be restricted.

@is_12 

Would you mind closing your earlier questions by marking appropriate response as correct?

Members have invested their time and efforts in helping you.

Disabling order now button for the agent 

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

@Ankur Bawiskarafter showing the alert message, I need to disable the order now button

 

Thanks, 

@is_12 

Sorry but you can't disable the Order Now button without DOM manipulation which is not recommended practice.

I hope your Architect or Tech Lead or the person who has assigned this story knows this very well what's best practice and as a Lead their job is to Consult and provide the best solution.

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

@Ankur Bawiskarokay, Can you help me with the DOM manipulation. Let's give a try

 

Thanks