- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 03:02 AM - edited 11-09-2022 07:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 04:47 AM
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:-
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:-
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 03:15 AM - edited 11-09-2022 03:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 04:04 AM - edited 11-09-2022 05:00 AM
This CheckOut should not execute if the Current Logged in user is From Billing Support group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 04:47 AM
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:-
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:-
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 03:57 AM - edited 11-09-2022 03:59 AM
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");
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