- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 01:14 AM
I have a requirement, I have 10 groups which start with same prefix. While creating new INCs we need to restrict assigning assignment groups. Only members of those 10 groups can only assign new INCs to those 10 groups. Other group members while creating new INCs should receive a error message.
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 01:49 AM
Hello Raviteja,
I would avoid working with Client Scripts in this case. ServiceNow does not recommend this for data validation purposes.
To achieve your requirements you can use a business rule. However looking into an advanced reference qualifier would be more useful.
The reference qualifier would only return the assignment groups that are allowed to be selected at the time being. However you'd need to add a script part to check if the current record is new or already existing.
Anyway, let me first guide you through the business rule and if you want to look into reference qualifiers, let me know and I'll help you.
Business Rule
Create a new "onBefore" business rule that runs only on inserts.
The condition should check if the assigment_group.name starts with your values
Then add a simple abort action that will trigger if the condition is true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 02:57 AM
Hi Raviteja,
Below is what I have done.
I have created a custom role "Test" and assigned it to the User.
Now I have written a onChange Client Script which will run on change of Assignment Group. It will get the role of the caller by using GlideAjax.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(g_form.isNewRecord())
{
var ga = new GlideAjax('chkUserRole');
ga.addParam('sysparm_name','chkCallerUserRole');
ga.addParam('sysparm_caller',g_form.getValue('caller_id'));
ga.getXML(HelloWorldParse);
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false')
{
g_form.setValue("assignment_group", '');
g_form.showErrorBox("assignment_group", "Not Authorized to assign");
}
}
}
Now the Script Include code,
Name: chkUserRole
Client Callable: True
Code:
var chkUserRole = Class.create();
chkUserRole.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCallerUserRole: function() {
var caller = this.getParameter('sysparm_caller');
return gs.getUser().getUserByID(caller).hasRole('Test');
}
});
Please try and let me know if it fulfill your requirements.