Validation in Service portal

keval3
Tera Contributor

Hi All,

I have below requirement

 

In one of catalog item in the service portal when ever user select Target delivery date, Start time, End time and location variables. ( All variables have select box type) and user submit the ticket. after that when other user come and select the same value. at that time error should come. 

Kindly refer below SS for reference.

 

keval3_0-1717997528278.png

 

 

kindly let me know it is possible or not. and if possible then how to do it.

 

Thanks & Regards

KP

1 REPLY 1

Jaap
Tera Expert

Hi @keval3 ,

You can try something like this with client script and script include:

(function() {
    function onSubmit() {
        // Get the values of the variables
        var targetDeliveryDate = g_form.getValue('target_delivery_date');  // Replace with your variable name
        var startTime = g_form.getValue('start_time');  // Replace with your variable name
        var endTime = g_form.getValue('end_time');  // Replace with your variable name
        var location = g_form.getValue('location');  // Replace with your variable name

        // Make an asynchronous GlideAjax call to check for duplicates
        var ga = new GlideAjax('CheckDuplicateEntry');
        ga.addParam('sys_target', 'CheckDuplicate');
        ga.addParam('target_delivery_date', targetDeliveryDate);
        ga.addParam('start_time', startTime);
        ga.addParam('end_time', endTime);
        ga.addParam('location', location);
        ga.getXMLAnswer(function(response) {
            var answer = response.responseXML.documentElement.getAttribute('answer');
            if (answer == 'true') {
                g_form.showFieldMsg('target_delivery_date', 'This combination already exists!', 'error');
                g_form.addErrorMessage('This combination already exists!');
                return false;
            } else {
                g_form.submit();
            }
        });

        return false;
    }

    g_form.submit = onSubmit;
})();

 

Script Include:

var CheckDuplicateEntry = Class.create();
CheckDuplicateEntry.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    CheckDuplicate: function() {
        var targetDeliveryDate = this.getParameter('target_delivery_date');
        var startTime = this.getParameter('start_time');
        var endTime = this.getParameter('end_time');
        var location = this.getParameter('location');

        // Query the target table to check for existing records with the same values
        var gr = new GlideRecord('your_table_name');  // Replace 'your_table_name' with the actual table name
        gr.addQuery('target_delivery_date', targetDeliveryDate);
        gr.addQuery('start_time', startTime);
        gr.addQuery('end_time', endTime);
        gr.addQuery('location', location);
        gr.query();

        if (gr.next()) {
            return 'true';
        } else {
            return 'false';
        }
    }
});

Can you try that and let me know if it is working?

Regards,

Jaap

Was my comment helpful? Please mark as such! 🙂