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

Using business rules

devservicenow k
Tera Contributor

Using business rules

Need to stop creating a Catalog Requested Item

 

 

1 ACCEPTED SOLUTION

Hi @devservicenow k ,

As you are using it on portal getXMLWait() will not work.

The below code is tested and working fine.

Use below code

Create Catalog Client Script as below:-

GunjanKiratkar_0-1667997956315.png

function onSubmit() {
    //Type appropriate comment here, and begin script below	
    if (g_scratchpad.isFormValid)
        return true;
    var user = g_user.userID;
    var ga = new GlideAjax('MemberofAssignmentGroupCS'); //Name of the Script Include 
    ga.addParam('sysparm_name', 'assing'); //name of function in script include 
    ga.addParam('sysparm_group', "Billing Support");
    ga.getXMLAnswer(setAnswer);
    return false;


    function setAnswer(answer) {
        if (answer == 'true') {
            g_form.addErrorMessage("Can't Create the Request as you are member of Billing Support Group");
            return false;
        }
        var actionName = g_form.getActionName();
        g_scratchpad.isFormValid = true;
        g_form.submit(actionName);

    }
}

 

Script Include As below:-

GunjanKiratkar_1-1667998010514.png

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

	assing: function() {
        var g = this.getParameter('sysparm_group');
        if (gs.getUser().isMemberOf(g)) {
            return true;
        } else {
            return false;
        }
    },
    type: 'MemberofAssignmentGroupCS'
});

 

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

4 REPLIES 4

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @devservicenow k ,

You will have to use the Sever side scripting as well here:-

Use below code :-

Client Script :-  

 

function onSubmit() {
   //Type appropriate comment here, and begin script below
	var ga = new GlideAjax('MemberofAssignmentGroupCS');
    ga.addParam('sysparm_name', 'assing');
    ga.addParam('sysparm_group', "Billing Support");
    ga.getXMLWait(memberOfAssignee);

    function memberOfAssignee(response) {
        var ans = response.responseXML.documentElement.getAttribute('answer');
		alert(ans);
        if (ans == 'true') {
            g_form.setValue('state',8);
           return false;
        } else {
            //Do Whatever you want to do
        }
    }
   
}

 

 

Script include :-

Client Callable true

 

var MemberofAssignmentGroupCS = Class.create();
MemberofAssignmentGroupCS.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    assing: function() {
        var g = this.getParameter('sysparm_group');
        if (gs.getUser().isMemberOf(g)) {
            return true;
        } else {
            return false;
        }
    },
    type: 'MemberofAssignmentGroupCS'
});

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

This CheckOut should not execute if the Current Logged in user is From Billing Support group

 

Hi @devservicenow k ,

As you are using it on portal getXMLWait() will not work.

The below code is tested and working fine.

Use below code

Create Catalog Client Script as below:-

GunjanKiratkar_0-1667997956315.png

function onSubmit() {
    //Type appropriate comment here, and begin script below	
    if (g_scratchpad.isFormValid)
        return true;
    var user = g_user.userID;
    var ga = new GlideAjax('MemberofAssignmentGroupCS'); //Name of the Script Include 
    ga.addParam('sysparm_name', 'assing'); //name of function in script include 
    ga.addParam('sysparm_group', "Billing Support");
    ga.getXMLAnswer(setAnswer);
    return false;


    function setAnswer(answer) {
        if (answer == 'true') {
            g_form.addErrorMessage("Can't Create the Request as you are member of Billing Support Group");
            return false;
        }
        var actionName = g_form.getActionName();
        g_scratchpad.isFormValid = true;
        g_form.submit(actionName);

    }
}

 

Script Include As below:-

GunjanKiratkar_1-1667998010514.png

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

	assing: function() {
        var g = this.getParameter('sysparm_group');
        if (gs.getUser().isMemberOf(g)) {
            return true;
        } else {
            return false;
        }
    },
    type: 'MemberofAssignmentGroupCS'
});

 

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

kamlesh kjmar
Mega Sage

Hi @devservicenow k ,

 

Reason your script is not working is because getMyGroups() method is not defined at client side, it's a server side method.

 

Now in your requirement the information against which you want to stop submission is available at server and the only way you can access that at client side is by using GlideAjax, but again there is a glitch. GlideAjax is asynchronous that means if you write it on submit, then by the time your callback funtion will execute your form will already be submitted, so you can't stop it from submission by that as well.

 

Now, the only way I see to achieve this is: 

 

1. Create a checkBox field and in it's default put the below code, also make sure to hide the field so that it's not visible on form (refer to the screen shot for help). 

 

     javascript:gs.getUser().isMemberOf("Billing Support");

 

kamleshkjmar_1-1667994909112.png

 

kamleshkjmar_2-1667994945362.png

 

 

 

2. Now if can write onSubmit client script with below code:

 

function onSubmit() {
    if (g_form.getValue("billing") == "true") // namme of your check box firld that you created
        return false;
}

 

 

This solution is when you have only one group members to restrict.

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh