OOB Reference qualifier on Configuration item

Alon Grod
Tera Expert

Can any one please tell me what this reference qualifier do?

 

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

 

Screen Shot 2023-01-16 at 17.43.54.png

1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Alon Grod ,

 

It is used to filter the available options for a reference field on a Configuration Item (CI) form in ServiceNow. The script uses the indexOf() method to check if the sys_class_name of the current record being viewed is "incident" or "problem". If it is not, the reference qualifier is cleared by returning an empty string. If the sys_class_name is "incident" or "problem", the script then applies a filter to the available options for the "operational_status" field.

The filter is created using the OpsStatusFilter object, which is being used to filter the options based on the "CreateTask" criteria. The by() method is used to specify the criteria, in this case it is "CreateTask". And join() method is used to join the filter.

So, the script is essentially checking if the current record is an incident or problem, and if it is, it filters the available options for the "operational_status" field based on the "CreateTask" criteria. This can be useful in situations where you want to limit the options that are available for a reference field based on certain conditions.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

3 REPLIES 3

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Alon Grod ,

 

It is used to filter the available options for a reference field on a Configuration Item (CI) form in ServiceNow. The script uses the indexOf() method to check if the sys_class_name of the current record being viewed is "incident" or "problem". If it is not, the reference qualifier is cleared by returning an empty string. If the sys_class_name is "incident" or "problem", the script then applies a filter to the available options for the "operational_status" field.

The filter is created using the OpsStatusFilter object, which is being used to filter the options based on the "CreateTask" criteria. The by() method is used to specify the criteria, in this case it is "CreateTask". And join() method is used to join the filter.

So, the script is essentially checking if the current record is an incident or problem, and if it is, it filters the available options for the "operational_status" field based on the "CreateTask" criteria. This can be useful in situations where you want to limit the options that are available for a reference field based on certain conditions.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi,

 

Where can we check the "CreateTask" criteria? in which table it exists?

Rahul RJ
Giga Sage
Giga Sage

@Alon Grod  This will return the list of CI where Operational Status is not one of Retired state.

 

 

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

 

 

 To understand the code you can try this in the background script 

 
 

 

 

var inc=new GlideRecord('problem');
inc.setLimit(1);
inc.query();
if(inc.next())
gs.info(['incident', 'problem'].indexOf(inc.sys_class_name + '') == -1?"inside if":"else if")

 

 

if the table is incident or problem it will return the list of CI where Operational Status is not one of Retired state.

To understand indexOf you refer link 

 

Regards,

RJ