Abort Form Submission
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 11:11 AM
Hi all,
I have the below requirement.
In my catalog form, I have a variable called vendor(string). When the form is submitted, the information is saved in a custom table with the same column name (vendor).
So, if I enter any text in the variable vendor field, it should check the data in the custom table vendor field and prevent form submission if duplicate data is found.
How could we achieve this?
- Labels:
-
Multiple Versions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 11:17 AM
Hello,
Thanks for posting your requirement.
What have you researched yourself? What do you think you need to do and where are you stuck?
What have you tried? etc.
Please mark reply as Helpful, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 06:35 PM
Thanks allen for the qucik reply,
Wrote the script include and called that in on change client script, seems its not working
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gaj = new GlideAjax('Vendor Checks');
gaj.addParam('sysparm_name','Vendor');
gaj.addParam('sysparm_field',newValue);
gaj.getXML(ajaxResponse);
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var values = answer.split(',');
if (values.indexOf(newValue) != -1)
{
alert("This value already exists");
}
}
Script include
Vendor : function()
{
var value = this.getParameter('sysparm_field');
var answers =[];
var gr = new GlideRecord('supplier_maintenance');
gr.addQuery('u_vendor','vendor_data');
gr.query();
while(gr.next())
{
answers.push(gr.value.toString());
}
return answers.toString();
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 06:38 PM
Hi are you getting the correct answer from Script Include? Can you place the alert in your client script and test like below
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var values = answer.split(',');
if (values.indexOf(newValue) != -1)
{
alert("This value already exists");
return false ; //abort submission you need this to abort submission
}
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:26 AM
Hi,
I'm glad you found my reply above Helpful.
For your script include and it not working, can you give more information about that? What have you tried thus far? What do your log entries say? What errors are you getting, etc.?
Please provide more information as to what "not working" means.
Additionally, in your script include, you're not using "value" which you're getting from the client script and you're also very close to using reserved words. I'd avoid using things like "value" or "answer(s)" when creating your own JavaScript variables.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!