Comments on: Stopping Record Submission https://servicenowguru.com/scripting/stopping-record-submission-servicenow/ ServiceNow Consulting Scripting Administration Development Tue, 28 May 2024 21:40:37 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: steve https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6552 Fri, 12 May 2017 14:23:08 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6552 I’m using the g_formsubmitted = false and return false; but these are not preventing the submission of my catalog item. please see my script below.

function onSubmit() {
	
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group', g_form.getValue('ad_group'));
grp.addQuery('user', g_form.getValue('ad_user'));
grp.query(groupMemberCallback);
   
function groupMemberCallback(grp){
//If user is a member of selected group
    if(grp.next()){
        //Do something
		g_form.showErrorBox("ad_user", "Error: user is already a group member " + 'ad_user.name' );
		g_form.submitted = false;
		return false;
    }
  
}

}

Basically I have a catalog item with two variables, a username and group name. I’m checking to see if the user is already a group member and if they are I’m displaying an error around the user variable and preventing the form from submitting, of course if the user is not a group member the form should submit. I can identify if the user is a group member but cannot prevent the form from submitting. Any insight you can offer is appreciated!

]]>
By: Mark Stanger https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6553 Fri, 12 May 2017 11:17:11 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6553 In reply to steve.

Try commenting everything else out but ‘return false;’ within your ‘if’ statement and adding an ‘Alert’ message right before ‘return false;’. Does the script show the alert? Does it prevent the submission? If it shows the alert and stops the submit correctly then your problem is probably with ‘g_form.showErrorBox’, which I don’t think is available in catalog client scripts and will need to be removed.

]]>
By: Mark Stanger https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6551 Fri, 10 Mar 2017 00:14:36 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6551 In reply to KG.

Great to hear. Thanks!

]]>
By: KG https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6550 Thu, 09 Mar 2017 23:20:22 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6550 Hi Mark,

This was just what I was looking for. Thank you!

]]>
By: Mark Stanger https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6549 Thu, 27 Oct 2016 11:18:44 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6549 In reply to Anshul.

It’s not possible to suppress that message unfortunately. You’re stuck with it so the best thing you can do is include an additional info message to clarify what it means.

]]>
By: Anshul https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6548 Thu, 27 Oct 2016 06:18:08 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6548 Hi Mark,
If i dont want to show invalid insert. Only want to show message. then?

]]>
By: Mark Stanger https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6547 Thu, 15 Sep 2016 16:15:51 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6547 In reply to Laszlo.

Normally you could use the javascript ‘scrollIntoView’, but I can’t get this to work in ServiceNow in my testing. You can google that and research it though and give it a try yourself.

]]>
By: Laszlo https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6546 Thu, 15 Sep 2016 15:34:00 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6546 Hello Mark, guys,

I have a long form, and in the middle of it there is a checkbox which has to be true when submit.
The script I use is the first one mentioend in the article, on submit client script. Works good!

I wonder how can I do that after the submit button and the alert popup the screen navigates on the form where the checkbox is placed? I mean scrolling up until the checkbox. Even some higlight error message would be nice under that checkbox there to say that please select this.

Thank you!

]]>
By: Mark Stanger https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6545 Wed, 11 Jun 2014 12:49:57 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6545 In reply to Frantisek.

You’re not doing anything wrong, but I think you’ve stumbled upon a ServiceNow bug that has probably been around since the beginning. ServiceNow has a ‘g_form.submitted’ check that goes along with ‘g_form.modified’ to make the dirty form capability work. That isn’t being set correctly when you abort with your client script. The solution is to set ‘g_form.submitted = false;’ right before your ‘return false;’ line in your script. I’ve updated the example script above with this fix. Thanks for the feedback!

]]>
By: Frantisek https://servicenowguru.com/scripting/stopping-record-submission-servicenow/#comment-6544 Wed, 11 Jun 2014 08:10:50 +0000 https://servicenowguru.wpengine.com/?p=933#comment-6544 Hi Mark,
I have client-side abort that is working well. However if the submission is aborted and the user clicks reload form, the form is reloaded immediatelly. There is not the usual alert ‘Changes have been made’. Am I doing something wrong?

if(g_form.getActionName() === 'sysverb_check_save'){
		
        if(g_form.modified){
            alert('Changes have been made. Save the form.');
            return false;
        }
}
]]>