User should not be able to submit catalog request if he is not a part of a particular group

Mishu
Tera Expert

User should not be able to submit catalog request  when Req type = Software and if he is not a part of a particular group. He should get an error message while submitting that "Not eligible for form submission".

 

Kindly help how to achieve this

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Mishu 

you can do this

1) create a string variable with highest order, set the flag in default value something like this, then hide this variable so that it doesn't show to user

javascript: gs.getUser().isMemberOf('Group ABC'); // give the group name here

2) use onSubmit catalog client script to stop the submission

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var reqTyp = g_form.getValue('request_type');
    if (reqTyp == 'Software' && g_form.getValue('hiddenVariable').toString() == 'true') {
        alert('You cannot submit this request');
        return false;
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Runjay Patel
Giga Sage

Hi @Mishu ,

 

You can write onSubmit catalog client script with below code

Client script code

function onSubmit() {
   //Type appropriate comment here, and begin script below
var reqTyp = g_form.getValue('request_type');
if(reqTyp == 'Software'){
var ga = new GlideAjax('UserUtils');
    ga.addParam('sysparm_name', 'checkGroupUser');
   
    ga.getXML(checkGroupUser);
    function ValidatecheckGroupUserVipUser(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        
        if (answer=='true') 
          return false;
		
		}
}

}

 

Server side code: create a script include with name UserUtils with client callable.

var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkGroupUser: function() {
        
      return gs.getUser().isMemberOf('Your Group Name');
    },
    type: 'UserUtils'
});

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

User is still able to submit the form

Ankur Bawiskar
Tera Patron
Tera Patron

@Mishu 

you can do this

1) create a string variable with highest order, set the flag in default value something like this, then hide this variable so that it doesn't show to user

javascript: gs.getUser().isMemberOf('Group ABC'); // give the group name here

2) use onSubmit catalog client script to stop the submission

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var reqTyp = g_form.getValue('request_type');
    if (reqTyp == 'Software' && g_form.getValue('hiddenVariable').toString() == 'true') {
        alert('You cannot submit this request');
        return false;
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Mishu 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader