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

This is Script include

find_real_file.png

Below Client script

find_real_file.png

Sure. No Change in Script Include needed(Just make sure CLient Callable is checked) as shown below.

find_real_file.png

Please use the modified Client Script below:

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(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

}

 

I Have tested this and is working correctly. Let me know if you stillf ace an issue:

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 

alert is working fine 

it is not going to if condition

Regards

Shiva

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