Restrict the form submission if the record is already there in the table

Community Alums
Not applicable

Hi All, 

 

Having a requirement that, 

we have a catalog form through that we are trying to insert the record in the software model table- cmdb_software_product_model

we have below fields as required. 

chanti1_0-1709058596882.png

in the above image we have the sample data in the fields. 

we need to restrict the form submission if the record with the same parameters exist in the software model table. 

Throw an alert and restrict the form submission. 

we need to validate the three parameters in the software table like Product, publisher, version. 

if we can validate the entered data to table record data then if exist restrict the form submission. 

 

 

Any suggestion to achieve this..

 

Thanks. 

 

4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

is this a catalog item or record producer?

If it is a record producer, you can add current.setAbortAction(true) in the record producer script.

 

If it is a catalog item, you may need to write an onsubmit and do glideajax or allow user to submit and later reject it and notify the user that the record already exists.


Please mark this response as correct or helpful if it assisted you with your question.

Community Alums
Not applicable

Hi @SanjivMeher 

Thanks for your swift response. 

its a catalog item we are having. 

is there any reference of the onSubmit script to get it validated of the three fields on the form to the table.

 

Any suggestions.  

 

Something like this

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579

Refer this article too

https://www.servicenow.com/community/developer-blog/how-to-async-glideajax-in-an-onsubmit-script/ba-...

 


Please mark this response as correct or helpful if it assisted you with your question.

Sumanth16
Kilo Patron

Hi @Community Alums ,

 

Please change the below script according to your query:

 

 

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;
        }
}

 

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;

},

 

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda