The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Reference qualifier for cI

Pratiksha KC
Tera Guru

 

 

We have a requirement to update the reference qualifier for the Configuration Item field on the Incident form using a dictionary override.

How can we implement a reference qualifier so that the field only displays CIs from the cmdb_ci table where:

  • The "Generic CI" flag (true/false) is set to true,

  • The CI belongs to the ManagedCI (principal class),

  • The CI is not in Install Status = Retired, and

  • All existing CIs in cmdb_ci with names starting with “Generic CI” are automatically flagged as true and included in the filter?

Currently, the existing reference qualifier for the CI field is:

 

 
javascript: ['incident', 'problem'].indexOf(current.sys_class_name + '') == -1? '' : 'operational_statusNOT IN' + new OpsStatusFilter('cmdb_ci').by('CreateTask').join()

 

 

The dictionary override uses:

 

javascript:new TaskUtils().getConfigurationItemFilter(current);
 

Given that we cannot modify the TaskUtils script include, how can this requirement be achieved using a dictionary override?

1 ACCEPTED SOLUTION

G Ponsekar
Giga Guru

Hi @Pratiksha KC ,

 

To implement this reference qualifier, you will need to create a new Script Include and then reference it in a Dictionary Override for the cmdb_ci field on the Incident table. Since you cannot modify the existing TaskUtils script include, this approach will avoid conflicts

 

Sample Script Include: 

Name : IncidentCIRefQualifier

javascript
var IncidentCIRefQualifier = Class.create();
IncidentCIRefQualifier.prototype = {
    initialize: function() {},

    getRefQual: function(current) {
        var genericCIs = this.getGenericCIs();
        var principalClass = this.getPrincipalClasses();
        var retiredStatus = 'Retired';

        var encodedQuery = "install_status!=" + retiredStatus;        encodedQuery += "^ORgeneric_ci=true";
        encodedQuery += "^ORsys_idIN" + genericCIs;
encodedQuery += "^<field_name>IN" + principalClass;
return encodedQuery; }, // Helper function to find CIs with names starting with "Generic CI" getGenericCIs: function() { var ciArray = []; var ciGr = new GlideRecord('cmdb_ci'); ciGr.addQuery('name', 'STARTSWITH', 'Generic CI'); ciGr.query(); while (ciGr.next()) { ciArray.push(ciGr.getUniqueValue()); } return ciArray.join(','); }, // Helper function to get CIs from Principal Classes getPrincipalClasses: function() { //write logic to return CI belongs to Managed Cis }, type: 'IncidentCIRefQualifier'};

And In dictionary override, you can use

javascript&colon; new IncidentCIRefQualifier().getRefQual(current);

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Pratiksha KC 

you can create your own script include, add filter logic there and then call that in the dictionary override.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

RaghavSh
Kilo Patron

You need to created your own script include and add that in the dictionary override.

The Qualifiers you mentioned looks simple, you can achieve this with  GlideRecord with encoded query on cmdb_ci table.


Raghav
MVP 2023
LinkedIn

G Ponsekar
Giga Guru

Hi @Pratiksha KC ,

 

To implement this reference qualifier, you will need to create a new Script Include and then reference it in a Dictionary Override for the cmdb_ci field on the Incident table. Since you cannot modify the existing TaskUtils script include, this approach will avoid conflicts

 

Sample Script Include: 

Name : IncidentCIRefQualifier

javascript
var IncidentCIRefQualifier = Class.create();
IncidentCIRefQualifier.prototype = {
    initialize: function() {},

    getRefQual: function(current) {
        var genericCIs = this.getGenericCIs();
        var principalClass = this.getPrincipalClasses();
        var retiredStatus = 'Retired';

        var encodedQuery = "install_status!=" + retiredStatus;        encodedQuery += "^ORgeneric_ci=true";
        encodedQuery += "^ORsys_idIN" + genericCIs;
encodedQuery += "^<field_name>IN" + principalClass;
return encodedQuery; }, // Helper function to find CIs with names starting with "Generic CI" getGenericCIs: function() { var ciArray = []; var ciGr = new GlideRecord('cmdb_ci'); ciGr.addQuery('name', 'STARTSWITH', 'Generic CI'); ciGr.query(); while (ciGr.next()) { ciArray.push(ciGr.getUniqueValue()); } return ciArray.join(','); }, // Helper function to get CIs from Principal Classes getPrincipalClasses: function() { //write logic to return CI belongs to Managed Cis }, type: 'IncidentCIRefQualifier'};

And In dictionary override, you can use

javascript&colon; new IncidentCIRefQualifier().getRefQual(current);

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP