Restrict form submission when the script include return a value to onsubmit client script.

Sangeetha7996
Tera Contributor
If the user selects a particular Business service (reference field) in the incident record producer, it should restrict the form submission. For others it should allow.
Business service field refers to the cmdb table. In the cmdb table, we have an attribute that holds the sys id of its dedicated record producer/ catalog form.
We have used onsubmit client script and script include to retrieve the sys id of the record producer from the cmdb table. If it retrieve sys id then form submission has to disabled.
 
Script include: client callable is enabled
var recordProducerNavigationUrl = Class.create();
recordProducerNavigationUrl.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getrecprodid: function() {
        var buscId = this.getParameter('sysparm_busc');
        var recordProdId = new GlideRecord('cmdb_ci_service');
        recordProdId.addQuery('sys_id', buscId);
        recordProdId.query();
        if (recordProdId.next()) {
            var result = recordProdId.u_incident_record_producer.toString();
            return JSON.stringify(result);

        } else {
            var resultE = '';
            return JSON.stringify(resultE);
        }
    },
    type: 'recordProducerNavigationUrl'
});
 
Client Script: 
function onSubmit() {
 
    if (!g_form.ajaxComplete) {
        ajaxCall();
        return false;
    }
}
 
function ajaxCall() {
 
    var busc = g_form.getValue('business_service');
    var instance = new GlideAjax('recordProducerNavigationUrl');
    instance.addParam('sysparm_name', 'getrecprodid');
    instance.addParam('sysparm_busc', busc);
    instance.getXMLAnswer(function(response) {
g_form.addInfoMessage(response);
        if (response) {
            g_form.ajaxComplete = true;
            g_form.submit();
 
        }
 
    });
5 REPLIES 5

@Sangeetha7996 - Understanding your requirement- In script include - you write logic to  check if the sys_id record producer is present in that Business Service table or not. If yes then should return true else return false.

Next in On change Client script - on change of variable you will select Business Service.

where call the script include function using Glide ajax and get response. If that response it is true then write "return false;" to restrict form submission. Else allow to submit form by writing "return true;". Hope it helps.

 

Please mark my response as helpful/correct if it helps.

Regards,

Priyanka Salunke