- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 10:29 AM
Hi All,
On the Task form is the Business Service reference field to cmdb_ci_service.
Today, I have an override ref qual on the Business Service Field when the form is the Incident so when you click on the lookup you are returned certain business service. This Ref Qual works:
javascript: "operational_status=1^"+ (current.category.nil() ? 'u_incident_categoryISNOTEMPTY' : 'u_incident_category=' + current.category)
Now I need this Ref Qual to be 'dynamic'.
If the assignment_group is "A" then the Ref Qual should only be where "operational_status=1"
ELSE the Ref Qual should remain
javascript: "operational_status=1^"+ (current.category.nil() ? 'u_incident_categoryISNOTEMPTY' : 'u_incident_category=' + current.category)
There should be enough space in the Ref Qual field to accommodate an IF statement but every attempt I've tried does not work.
I have tried called a script include, but that has not worked either.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 11:40 AM
I took a stab at it real quick. So the ref qual would look something like:
javascript: new TestScriptInclude().businessServiceRefQual(current);
And the script include:
var TestScriptInclude = Class.create();
TestScriptInclude.prototype = {
initialize: function() {
},
businessServiceRefQual: function(incident) {
var query = '';
if(incident.assignment_group == '3647376ddbb58b04f8d57fc88c961975')
query = 'operational_status=1';
else
if(JSUtil.nil(incident.category))
query = 'operational_status=1^u_incident_categoryISNOTEMPTY';
else
query = 'operational_status=1^u_incident_category= ' + incident.category;
return query;
},
type: 'TestScriptInclude'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 10:46 AM
Can you show what your script include looks like?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 10:54 AM
This was the latest Ref Qual I tried: Thinking I could add the IF here and forgo the SI.
javascript:if(assignment_group == '3647376ddbb58b04f8d57fc88c961975') "operational_status=1^"EQ';else 'operational_status=1^EQ'+ (current.category.nil() ? 'u_incident_categoryISNOTEMPTY' : 'u_incident_category=' + current.category)
i can't find a copy of the latest script include I tried. I put everything back in DEV because I had to move onto another task. It was basically me calling the SI and trying to return a list if CI when group= A and a list of CI when the group isn't A.
If group was A I would query cmdb_ci_service where operational_status is 1 and if not group A then I would use the existing ref qual to get the list of CI 'operational_status=1^EQ'+ (current.category.nil() ? 'u_incident_categoryISNOTEMPTY' : 'u_incident_category=' + current.category)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 10:59 AM
With a lengthy ref qual, you'll likely need to go down the SI route. I might refer to an article like this: Advanced Reference Qualifier Using a Script Include - ServiceNow Guru to make sure you were just returning the value in the proper format. When using a SI in a reference qualifier, you'll want to make sure the return value is a stringified encoded query, not the resulting if statement you would use if writing it directly in the ref qual field itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 11:07 AM
It's the syntax that is the struggle. Since the text appeared to fit in the Ref Qual field I took a stab at that first thinking it would have easier syntax.
When I get time I'll just have to continue trial and error on the SI. That article is one that I referenced when I tried to create the SI.
I gave it a few hours today but had to move on.
Thanks.