The CreatorCon Call for Content is officially open! Get started here.

Script for Client script if a user is a part of A assignment group then user can get priority=1 .If user is not part of A assignment group then user should get pop-up

shiva narayana
Kilo Contributor

Hello 

Script for Client script   if a user is a part of A assignment group then user can get priority=1 .If user is not part of A assignment group then user should get pop-up for submitting priority=1

 

 

 

1 ACCEPTED SOLUTION

Can you put an alert as shown below:

alert(typeof answer);

This will help in debugging what type of value is getting returned whether it is string or boolean and according you can put quotes in If block or not.

Ideally it should be string returned from Script Include and I have tested it and working fine . 

Please see screenshot below:

find_real_file.png

Sharing Script Include and Client Script again for reference:

Script Include:

var checkGroupMember = Class.create();
checkGroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	checkGroup : function(){
		var grp = gs.getUser().isMemberOf('Analysts');
		return grp;
	},

    type: 'checkGroupMember'
});

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue == 1) {
        var ga = new GlideAjax('checkGroupMember'); // Script Include Name here
        ga.addParam('sysparm_name', 'checkGroup'); // Your Function Name here
        ga.getXML(valdiatePriority);
    }

    function valdiatePriority(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		alert(typeof answer);
        if (answer == 'false') {
            g_form.addErrorMessage('Your Message Here');
            g_form.setValue('priority', oldValue); // To revert to Old Value

        }
    }
    //Type appropriate comment here, and begin script below

}

 

Put alert in different line on client side and see what value is coming and let me know..

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

13 REPLIES 13

Nope, you will require a Server Side script can be a BR or a Script Include here so that you can validate that if User is a part of a Group or not.

On Client side I don't think this is possible to validate, you will need a Server script to check.

Display BR is easy and simple to implement rather than a Script include which is not needed here but if you want can be used as well.

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi 

Thank you 

I will go with Script Include 

Could you please  show me how can I use script  include 

 

In that case you need to create a Client callable Script Include and use the script below to check if Logged in User is a Part of the Group you want to check as shown below:

var checkGroupMember = Class.create();
checkGroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	checkGroup : function(){
		var grp = gs.getUser().isMemberOf('GroupName here');
		return grp;
	},

    type: 'checkGroupMember'
});

find_real_file.png

Now you need to modify your Client script as well. Please use the script below to validate your requirement:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue == 1) {
        var ga = new GlideAjax('checkGroupMember'); // Script Include Name here
        ga.addParam('sysparm_name', 'checkGroup'); // Your Function Name here
        ga.getXML(valdiatePriority);
    }

    function valdiatePriority(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer == false) {
            g_form.addErrorMessage('Your Message Here');
            g_form.setValue('priority', oldValue); // To revert to Old Value
            
        }
    }


//Type appropriate comment here, and begin script below

}

 

find_real_file.png

 

This way you can validate based on Script Include and Client Script. If you need to check for multiple group then put an OR condition in your script include.

 

Again will suggest go with Display BR as Script Include in this case will only increase complexity and maintainability, if this is just for learning purpose then it's okay.

I have shared both ways how you can achieve this.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi 

Thank you 

It is not working

Regards 

Shiva

Can you share your Script Include and Client script what you have written to assist you further?

I have tested the above code which I Posted and it works for me in my PDI.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke