Pop Notification

PK14
Kilo Guru

Hi SN experts, 

I am writing an catalog client script to restrict user to not submit the ticket (on catalog item) if they are part of ServiceDesk assignment group but they can submit the request for others. 

 

Following is the script include : 

 

var CheckAssignmentGroup = Class.create();
CheckAssignmentGroup.prototype = {
initialize: function() {},
type: 'CheckAssignmentGroup'
};
CheckAssignmentGroup.isUserInGroup = function(groupName) {
var user = gs.getUser();
return user.isMemberOf(groupName);
};

 

and client script is 
function onSubmit() {
var groupName = "ServiceDeskDL"; 
var ga = new GlideAjax('CheckAssignmentGroup');
ga.addParam('sysparm_name', 'isUserInGroup');
ga.addParam('sysparm_groupName', groupName);
ga.getXMLAnswer(function(response) {
if (response == 'true') {
alert("You are already a member of the ServiceDesk DL assignment group. Cannot submit the request.");
return false; // Prevent form submission
} else {
return true; // Allow form submission
}
});
}

Can you please help me on this or assist me the right path. 

Regards,

Priyanka

9 REPLIES 9

SANDEEP28
Mega Sage

@PK14 You need to create client callable script include if you want to call it from client scripts. You client script looks good. Create script include as below

 

SANDEEP28_0-1691404160039.png

 

Add below code in script section

 

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

    isUserInGroup: function() {
        var groupName = this.getParameter('sysparm_groupName');
        if (groupName)
            return gs.getUser().isMemberOf(groupName);
        else
            return false;
    },

    type: 'CheckAssignmentGroup'
});

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Hi Sandeep,

 

 I have already checked the client callable field but still the code doesn't seems to be working. 

 

Regards,

Priyanka

SANDEEP28
Mega Sage

@PK14 Share your script include and client script code here

the main question already consists the script include and client script code

 

Regards,

Priyanka