Not allow form to submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 08:16 AM
My requirement is to not allow users to submit the record producer form if already same short description and description has been entered in previous requests. I have written on submit client script where i have made a glideajax call in order to receive data from server which is checking whether the incident is having same combination of short description and description so everything is working fine but I am not able to execute return false once conditions match from the existing data and hence in all cases the form is getting submitted.
client script -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 08:34 AM - edited ‎11-25-2024 08:45 AM
I think the problem might be with your client script. Unless there is another need, you do not need to be setting any variable of "Flag" as true or false. You could do the following
client script -
function onSubmit() {
//Type appropriate comment here, and begin script below
var shortDescription = g_form.getValue('short_description');
var description = g_form.getValue('description');
var ga = new GlideAjax('inci');
ga.addParam('sysparm_name', 'fetch');
ga.addParam('sysparm_val', shortDescription);
ga.addParam('sysparm_valu', description);
if ((!shortDescription) && (!description)) {
return false;
}
ga.getXMLAnswer(canSubmit)
function canSubmit(answer){
if (answer) {
alert("An incident has already been created with this description and short description);
return false;
}
}};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 10:02 AM
Thank you for your help. Unfortunately, it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 11:37 AM
I do agree with some of the other posts - it's not the best requirement as it can lead to a lot of missed errors etc. That said, if you still need to move forward, one way to potentially combat the issue you were running into for the onSubmit client script is to instead do an onChange client script. Would be a little bit of a better experience for the end user and wouldn't allow the submission until fixed. You'd need to create two client scripts and two methods within the script include but it would look something like this (Specific to the description field)
CLIENT SCRIPT
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// var shortDescription = g_form.getValue('short_description');
var description = newValue;
var ga = new GlideAjax('getUserDetails');
ga.addParam('sysparm_name', 'fetch');
ga.addParam('sysparm_valu', description);
ga.getXMLAnswer(canSubmit);
function canSubmit(answer){
if (answer == "true") {
alert("An incident has already been created with this description");
return false;
}
}
}
SCRIPT INCLUDE
fetch: function() {
var k = this.getParameter('sysparm_valu');
var gr = new GlideRecord('incident');
// gr.addQuery('short_description', o);
gr.addQuery('description', k);
gr.query();
if (gr.next()) {
kt = 'true';
} else {
kt = 'false';
}
return kt;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 08:47 AM
Hi @kaushiki berter ,
I believe there could be a better approach than this. Even a comma, space or a full stop difference will make the form to Submit.
Push back the requirement to the clients.
Regards,
Najmuddin.