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

Filipe Cruz
Kilo Sage
Kilo Sage

Hello Charlotte,

Create an onSubmit Catalog client script that performs an Ajax call to the server to see if there is already one hr case opened. If so, abort the submit and display an error message stating that there is one hr case opened for that user.

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

Hi Filipe

because I'm not so good at scripting, can you provide me an example Catalog client script that performs an Ajax call to the server to see if there is an already one hr case opened please?

The script to abort submit and display error I know how to do 🙂

Many thanks!

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

Charlotte
Tera Contributor

Hi Filipe

thanks again for your advice. Can this also be an "onLoad" client script?

Because we don't want the employee doing all the effort of filing in a form, to see "onSubmit" that he can't submit the ticket 🙂