- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 12:26 AM
If record exist in the table, the catalog form should not allow to submit and should display the alert message with Record already exist. If it is new record the form is allowed to submit and insert the record.
But when Iam trying to submit the form with duplicate record, alert message is populating but form is submitted with data. It should not be allowed to submit the form, if it is duplicate.
Please find the below code, pls correct if anything wrong.
if (g_form.getValue('oss_gov_package_registry') == 'npm' || g_form.getValue('oss_gov_package_registry') == 'nuget') {
alert('inside npm :' + g_form.getValue('oss_gov_package_registry'));
//var ga1=new GlideAjax('InsertLicenseRecord');
ga1.addParam('sysparm_name', 'isRecordExistInOSSLibrary');
ga1.addParam('sysparm_packageName', g_form.getValue('package_name'));
ga1.addParam('sysparm_packageRegistry', g_form.getValue('oss_gov_package_registry'));
ga1.addParam('sysparm_packageVersion', g_form.getValue('oss_gov_version_number'));
ga1.getXML(validatePackage);
}
function validatePackage(response) {
result = response.responseXML.documentElement.getAttribute('answer');
alert("result" + result);
if (result == 'true') {
alert('Record is already exist so please submit the record with different value');
}
}
return false;
}
Script Include :
var ValidateOSSLibraryRecord = Class.create();
ValidateOSSLibraryRecord.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isRecordExistInOSSLibrary: function() {
gs.log('insertRecordOSSLibrary : npm : ');
var retVal = 'false';
var packageRegistry = this.getParameter('sysparm_packageRegistry');
var gr = new GlideRecord('u_oss_library');
if (packageRegistry == 'npm' || packageRegistry == 'nuget') {
var packageName = this.getParameter('sysparm_packageName');
var packVersion = this.getParameter('sysparm_packageVersion');
gs.info('Package Name : '+packageName);
gs.info('Package Version : '+packVersion);
//var gr = new GlideRecord('u_oss_library');
gr.addQuery('u_library_name', packageName);
//gr.addQuery('u_packagetype', packageRegistry);
gr.addQuery('u_version', packVersion);
gr.query();
if (gr.next()) {
gs.info('NPM/nuget Package Name is already exist');
retVal = 'true';
}
return retVal;
},
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 12:42 AM
Hello Suresh,
Please change your onSubmit client script to use getXMLWait:
if (g_form.getValue('oss_gov_package_registry') == 'npm' || g_form.getValue('oss_gov_package_registry') == 'nuget') {
alert('inside npm :' + g_form.getValue('oss_gov_package_registry'));
//var ga1=new GlideAjax('InsertLicenseRecord');
ga1.addParam('sysparm_name', 'isRecordExistInOSSLibrary');
ga1.addParam('sysparm_packageName', g_form.getValue('package_name'));
ga1.addParam('sysparm_packageRegistry', g_form.getValue('oss_gov_package_registry'));
ga1.addParam('sysparm_packageVersion', g_form.getValue('oss_gov_version_number'));
ga1.getXMLWait();
var recordExist =ga1.getAnswer();
if (recordExist == "true") {
alert('Record is already exist so please submit the record with different value');
return false;
}
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 12:32 AM
Hi,
you are using Asynchronous GlideAjax so by the time the script include function returns the data the form might get submitted.
Refer this link for alternate approach
Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit
How To: Async GlideAjax in an onSubmit script
Asynchronous onSubmit Catalog/Client Scripts in ServiceNow
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2022 12:07 AM
@Suresh
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 03:21 AM
@Suresh
getXMLWait() won't work in portal so it won't work.
You need to try the links I shared which has the workaround for this.
Did you check those?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 12:42 AM
Hello Suresh,
Please change your onSubmit client script to use getXMLWait:
if (g_form.getValue('oss_gov_package_registry') == 'npm' || g_form.getValue('oss_gov_package_registry') == 'nuget') {
alert('inside npm :' + g_form.getValue('oss_gov_package_registry'));
//var ga1=new GlideAjax('InsertLicenseRecord');
ga1.addParam('sysparm_name', 'isRecordExistInOSSLibrary');
ga1.addParam('sysparm_packageName', g_form.getValue('package_name'));
ga1.addParam('sysparm_packageRegistry', g_form.getValue('oss_gov_package_registry'));
ga1.addParam('sysparm_packageVersion', g_form.getValue('oss_gov_version_number'));
ga1.getXMLWait();
var recordExist =ga1.getAnswer();
if (recordExist == "true") {
alert('Record is already exist so please submit the record with different value');
return false;
}
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks