
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2015 11:56 AM
Hi all,
I have a request to require a related problem record before priority 1 and 2 incidents can be resolved, which we've accomplished with an onSubmit client script. But I'd like to restrict this to certain groups, while also making it easy for groups to 'opt in/out' of the functionality in the future. I created a new true/false field on the sys_user_group table, named u_require_problem, but I'm not able to pull the value of the field into my script.
I added the field to the form and plan to hide it with a UI Policy, and have validated that the field is checked on the group for my test incidents.
Lines 6 & 7 are where I'm trying to get the value of the new field so I can use it in line 9. The script successfully prevents resolution for P1/P2s with no related problem, but I haven't been able to successfully populate my probMgmt variable.
function onSubmit() {
//If p1 or p2 incident state == resolved and problem ID is blank
var pri = g_form.getValue('priority');
var state = g_form.getValue('state');
var prob = g_form.getValue('problem_id');
var probMgmt = g_form.getValue('u_require_problem');
alert(probMgmt);
if(state == '6' && (pri == '1' || pri == '2') && prob == ''){
alert('A problem is required for all P1 and P2 incidents.');
return false;
}
I've tried getValue, getDisplayValue and getBooleanValue (referenced in GlideForm (g form) - ServiceNow Wiki), getBooleanValue returns a 'not a function' error on the form and the others return a null value. Is there an easier way to accomplish this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2015 05:48 PM
The issue is likely because the field you are trying to access is in the related group table, I assume you are just showing this value on the form by dot walking. You really don't need it on the form to accomplish what you need. But you will need to get the related group record to check the value. Out of the box there is a client script on Incident that populates the incident location value with the callers location. I would look at that script, specifically how it's using getReference to get the caller user record to lookup the location value. You can use a similar approach to get the u_require_problem value from the group record. Another option is to make an Ajax call to lookup the value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2015 01:03 PM
Are you trying to make it based on the currently logged in user or based on the assignment group on the Incident record?
If it's supposed to be based on the currently logged in user, then you would be better off creating a role and adding that to the groups you want to be required to have a related problem. Then you could use a g_user.hasRole('<role>') to see if the current user should be required to do it.
If it's based on the assignment group, then you need to use a GlideRecord query to get the value of the field on the group record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2015 05:48 PM
The issue is likely because the field you are trying to access is in the related group table, I assume you are just showing this value on the form by dot walking. You really don't need it on the form to accomplish what you need. But you will need to get the related group record to check the value. Out of the box there is a client script on Incident that populates the incident location value with the callers location. I would look at that script, specifically how it's using getReference to get the caller user record to lookup the location value. You can use a similar approach to get the u_require_problem value from the group record. Another option is to make an Ajax call to lookup the value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2015 08:24 PM
The out of box location and caller vip scripts helped immensely, thank you! This is what I have going now, so far so good:
function onSubmit() {
var group = g_form.getReference('assignment_group');
var pri = g_form.getValue('priority');
var state = g_form.getValue('state');
var probID = g_form.getValue('problem_id');
if (group.u_require_problem == 'true' && state == '6' && (pri == '1' || pri == '2') && probID == '') {
alert('A problem is required for all P1 and P2 incidents.');
return false;
}
}
But I realize I'm doing exactly what the wiki tells me not to do. When I did it the right way with a callback function, everything seems to work up to the alert point, where the incident is resolved even when the alert is triggered. Is there an example of using getReference like this for an onSubmit script instead of an onChange?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2015 03:50 AM
The getReference() function requires a lookup to the server client side so it's not the most efficient, which is what the Wiki is telling you. Sometimes you cannot avoid it though. Fortunately you are making the call onSubmit which will occur less often than onChange or onLoad.
Another alternative and maybe better one is to put this logic in the Resolve UI action. This way it performs the validation only when the ticket is being resolved. The out of the box Resolve Incident UI action performs some things client side and well as server side. It requires a comment, close code, and close notes. You could also have it check the flag in the group and require a problem as well.
Either will work though.