Prevent user from submitting new ticket if there is still an open ticket

Charlotte
Tera Contributor

How can I prevent a user from submitting a new HR Case via record producer "Request move", if there is still an open HR Case for "Request move" for this user? So only 1 open HR Case per user for a specific HR Service can be possible. 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Hi Charlotte,

Here is an example of a Client script: (in this case is an onChange, but you want to do this in an onSubmit Client script).

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }

    var test = g_form.getValue('enter your reference field');
    var check = new GlideAjax('your script include name');
    check.addParam('sysparm_name', 'script include function name');
    check.addParam('sysparm_comp', test);
    check.getXML(analyzeResponse);

    function analyzeResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
    }
}

Please notice that the GlideAjax is calling a specific script include, the sysparm_name parameter will contain the method name in that script include, and sysparm_comp is one parameter to pass.

Then your script include should look like this: (Must be checked as client callable, otherwise it will not work!)

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

    test: function() {
        var test = this.getParameter('sysparm_comp');
        var grp = new GlideRecord('sys_user');
        grp.addQuery('name', test);
        grp.query();
        while (grp.next()) {
            //now you can perform your query here.
        }
    },

    type: 'test'
});

 



IF you want more details, please refer to the following Servicenow Product Documentation link:

https://docs.servicenow.com/en-US/bundle/sandiego-application-development/page/script/ajax/topic/p_A...

Hope this helps you!!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

View solution in original post

5 REPLIES 5

Hi Charlotte,

Sure!! You can perform that validation right at the beginning, when the form is loaded! You can present some kind of message to the user to inform that there is already a "Request move" case open.

Also keep the onSubmit client script active since you might have users trying to submit that second case (and you want to avoid that case from being created).

Hope this helps!

Let me know if you need further assistance on this topic!!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz