
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2014 07:32 AM
Hello!
I am trying to write a script to populate the assignment group when the assigned to field has a name in it. For example, Jane Smith belongs to group Infrastructure. I assign an incident to Jane Smith and the assignment group changes from empty to "Infrastructure" since that is the group she belongs to. I am new to Service Now and I'm not too familiar with the java script. I'm thinking I will have to write an Assignment Rule but I am not sure on how to start it. Also, we have the "Assign to Me" button on the Incident form and would like the button to do the same. If I click on "Assign to Me",the incident will be assigned to me and the assignment group will be auto-populated with my group.
for the button, in the UI Action, I had this:
action.setRedirectURL(current);
current.assigned_to = gs.getUserID();
current.assignment_group = gs.getMyGroups();
current.update();
However, that is not working for me.
I would like some help in figuring out how I can accomplish this. Please let me know what I can do.
Thank you!!!
Yeny.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2014 10:19 AM
Hi Yeny,
You will need to ensure that you have scripts enabled for mobile devices.
Configuring the Smartphone Interface - ServiceNow Wiki
Since it sounds like you need to have the Assignment group populated in real time and not in a business rule, the only suggestion I would have for that is an onChange client script for the Assigned to field. That script could run an asynchronous GlideAjax call to perform the same function that is in the business rule that I suggested. The return value from that script will be the assignment group and by using "g_form.setValue(<field name>, value)", you can have the assignment group populated.
You could also use "g_form.getReference(fieldName, callback)" with the callback function so not to hang the client on the script processing. In the callback function, the return value can also be set by using "g_form.setValue(<field name>, value)"
Mobile Client GlideForm (g form) Scripting - ServiceNow Wiki
In regards to your UI Policy with the Service Desk value, you can condition it out to not clear the value if the assigned to is empty and the assignment group is Service Desk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2014 10:19 AM
Hi Yeny,
You will need to ensure that you have scripts enabled for mobile devices.
Configuring the Smartphone Interface - ServiceNow Wiki
Since it sounds like you need to have the Assignment group populated in real time and not in a business rule, the only suggestion I would have for that is an onChange client script for the Assigned to field. That script could run an asynchronous GlideAjax call to perform the same function that is in the business rule that I suggested. The return value from that script will be the assignment group and by using "g_form.setValue(<field name>, value)", you can have the assignment group populated.
You could also use "g_form.getReference(fieldName, callback)" with the callback function so not to hang the client on the script processing. In the callback function, the return value can also be set by using "g_form.setValue(<field name>, value)"
Mobile Client GlideForm (g form) Scripting - ServiceNow Wiki
In regards to your UI Policy with the Service Desk value, you can condition it out to not clear the value if the assigned to is empty and the assignment group is Service Desk.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2014 07:53 AM
Thank you for your help Mike. I was able to create the onChange client script and a conditioned UI policy for the service desk value. It works now. Thank you all for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2014 08:19 AM
You're welcome!
Please remember to mark my answers as correct if they answered your question.
Kind Regards,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2015 01:45 AM
I am trying to use this Mike P's suggestion but I think something is wrong with my business rule. Can you pls. review below and advise...
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
setDefaultGrp(current.assigned_to);
var assignedTo = current.assigned_to.getMyGroups();
var assignment = current.assignment_group;
gs.setValue('assignment', assignedTo);
function setDefaultGrp(assignment){
var defGroup = new GlideRecord('sys_user');
defGroup.get(assignedTo);
current.assignment_group = defGroup.u_primary_group;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2015 04:50 PM
Hi Giovanni,
It's not fully clear what all you are trying to accomplish in lines 8-10.
I've updated the code you had and removed the call for the function as this is not needed.
Please advise with more detail what you are trying to accomplish with your business rule.
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
var defGroup = new GlideRecord('sys_user');
defGroup.get(current.assigned_to);
current.assignment_group = defGroup.u_primary_group;
//var assignedTo = current.assigned_to.getMyGroups();
//var assignment = current.assignment_group;
//gs.setValue('assignment', assignedTo);
//function setDefaultGrp(assignment){
// var defGroup = new GlideRecord('sys_user');
// defGroup.get(assignedTo);
// current.assignment_group = defGroup.u_primary_group;
//}
}
Kind Regards,
Mike