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

shloke04
Kilo Patron

Hi,

Please see the steps below to achieve your requirement:

1) Create a Display Business Rule on Incident Table and use the script below:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	g_scratchpad.checkGroup =gs.getUser().isMemberOf('group Name here');
})(current, previous);

find_real_file.png

Now

write an On Change Client script on Priority field and use the script below:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	if(newValue == 1){
		if(g_scratchpad.checkGroup == false){
			g_form.addErrorMessage('Your Message Here');
		}
	}

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

find_real_file.png

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

So if User is not a part of the group you are checking then it will throw an error message and you can clear the value of priority field or set it back to it's old value as well.

 

Regards,

Shloke

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

Regards,
Shloke

You can use below two lines which ever you want in your client script shown above:

g_form.setValue('priority',oldValue);// To revert to Old Value
g_form.clearValue('priority');// To clear out the value

Regards,

Shloke

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

Regards,
Shloke

Hi 

Thank you 

Is any There any way we can use only client script By not using BR

If any please help me