Logged in user should be a part of a group then only he can submit the form, other users cannot

Mishu
Tera Expert

Hello Experts,

 

I am trying to achieve this requirement - User should not be able to submit a catalog request if he is not a part of the software group.
Tried with below On submit Client script and Script Include, but its not giving result, Can u plz help whats wrong here ?

 

 

On Submit Client Script :

 

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var part = g_form.getValue('name_of_the_partition');
    var reqTyp = g_form.getValue('request_type');


    if ((part == 'major || 'minor') && reqTyp == "software") {
        var ga = new GlideAjax('UserUtils');
        ga.addParam('sysparm_name', 'checkGroupUser');
        ga.getXML(checkGroupUser);
    }

function checkGroupUser(response) {
    var result = response.responseXML.documentElement.getAttribute("answer");
    if (result == 'true') {
        return true;
    } else {
        g_form.addErrorMessage("User not eligible to submit the form");
        return false;
    }
}
}

 

 

Script Include:

 

 

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

 

 

9 REPLIES 9

@Mishu 

 

You can check the Advanced checkbox and write the script to check for the condition within this. Refer https://www.servicenow.com/community/hrsd-forum/how-to-create-user-criteria-with-the-script-to-check...

 


Please mark this response as correct and helpful if it assisted you with your question.

Could you help me with the query script on how to check the variables request type, part  and the group user condition in User criteria, the one you shared is not relevant

@Mishu 

 

I observed an issue with your Script Include. You are passing the group name instead of the group sys_id. Replace the group name "TMG Catalog Users" with the sys_id of this group and retry. It should work.


Please mark this response as correct and helpful if it assisted you with your question.

It tried, it made no difference @Amit Verma 

Mishu
Tera Expert

@Ankur Bawiskar @Willem 

 

Can you please help me here ?