The CreatorCon Call for Content is officially open! Get started here.

onsubmit client script with ajax ... stop submission

ggg
Giga Guru

I am trying to stop submission of a form if there are no recs in the related list.

i have an on submit client script with ajax call.

the ajax call returns the correct value,

but the submission is not halted.

the form closes and we go back to the list.

is it possible to do this via ajax?

if not, how?

1 ACCEPTED SOLUTION

ggg
Giga Guru

I am able to accomplish my requirement in another way:

In the ui action (server) Submit button I determine if the submit can go forward.

If not,

I use gs.addInfoMessage() to add a message to form;

set a status to "failed";

action.setRedirectURL(current).

this does the job.

View solution in original post

9 REPLIES 9

Elijah Aromola
Mega Sage

Check for whatever your GlideAjax is returning and return false, such as:

var val = result // result of GlideAjax

if(val == false) {
    return false;
}

it works if i do not have an ajax call.

if i have the return false within the response function it does not stop on the form, the form closes and we go back to the list.

would you please try this with an ajax script and let me know your result?

is there another way to see if the form has any records in the related list ... in a child table?

The following worked for me. You would obviously have to change your script include function to check the amount of records in that list and return a value to then check.

//Script include

var communityTest = Class.create();
communityTest.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	testFunction:  function() {
		return "false"; 
	},
	
    type: 'communityTest'
});
//Client Script
function onSubmit() {
	var ga = new GlideAjax("communityTest");
	ga.addParam("sysparm_name", "testFunction");
	ga.getXMLWait();
    if (ga.getAnswer() == 'false') {
		g_form.addErrorMessage("Error")
		return false; 
	}
}