Reference Qualifier for Change Request form

HansellF
Mega Contributor

Hello folks!

 

I need help with a Dynamic Ref Qual field. 

 

From the change_request table form: 

1. My configuration item field (cmd_ci), needs to show the CIs related to the company previously selected,

   1.1 This field is from the Task table

   1.2 Field type "choice"

 

2. My Services field, needs to show the Terms and Conditions available for the company selected
2.1 Reference: clm_m2m_contract_and_terms
2.2 Field type: Reference

3 REPLIES 3

G Ponsekar
Giga Guru

Hi @HansellF ,

 

1. Create a script include
  • Give it a descriptive name (e.g., "ChangeRequestRefQualifiers").
  • Ensure the "Client callable" checkbox is checked.
  • Inside the script, you'll define functions to handle the logic for each dynamic reference qualifier. 
2. Define the reference qualifiers for your fields
 
2.1 For the configuration item (cmdb_ci) field
  • Navigate to the Change Request form and right-click on the "Configuration Item" field.
  • Select "Configure Dictionary".
  • Important: The Configuration Item field is likely defined on the Task table, which Change Request extends from. Instead of modifying the base dictionary entry, create a Dictionary Override for the Change Request table.
  • On the Dictionary Override, go to the "Reference Qual" field.
  • Enter a JavaScript call to your Script Include function, passing in the relevant field (the company field on your Change Request form) as a parameter. 
javascript
javascript<< put colon : after javascript >> new ChangeRequestRefQualifiers().getCompanyCIs(current.company);
 
  • In your Script Include (ChangeRequestRefQualifiers), define a function like this:
 
javascript
var ChangeRequestRefQualifiers = Class.create();
ChangeRequestRefQualifiers.prototype = {
    initialize: function() {},

    getCompanyCIs: function(companySysId) {
        var ciList = [];
        var gr = new GlideRecord('cmdb_ci');
        gr.addQuery('company', companySysId);
        gr.query();
        while (gr.next()) {
            ciList.push(gr.getUniqueValue()); 
        }
        return 'sys_idIN' + ciList.join(',');
    },

    type: 'ChangeRequestRefQualifiers'};
 
This script will filter the Configuration Item list to show only CIs associated with the selected company. 
 
2.2 For the services field
  • Right-click on the "Services" field and select "Configure Dictionary".
  • On the "Reference Specifications" tab, choose "Advanced" for the "Use Reference Qualifier" field.
  • In the "Reference qual" field, call a function in your Script Include, passing in the company field from the Change Request form. 
javascript
javascript&colon; new ChangeRequestRefQualifiers().getCompanyTerms(current.company);
  • Add the following function to your Script Include (ChangeRequestRefQualifiers):
 
javascript
getCompanyTerms: function(companySysId) {
    var termsList = [];
    var gr = new GlideRecord('clm_m2m_contract_and_terms'); // Table for Terms and Conditions    gr.addQuery('company', companySysId); // Assuming a 'company' field on this table    gr.query();
    while (gr.next()) {
        termsList.push(gr.getUniqueValue());
    }
    return 'sys_idIN' + termsList.join(',');
},
 
This script will filter the Services list to show only Terms and Conditions available for the selected company.
 

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

 

Thanks, GP

Ankur Bawiskar
Tera Patron
Tera Patron

@HansellF 

1. My configuration item field (cmd_ci), needs to show the CIs related to the company previously selected,

-> the CI field is at task level, so you should create a dictionary override for Change Request table and then add your ref qualifier there

AnkurBawiskar_1-1755850129707.pngAnkurBawiskar_2-1755850161698.png

 

-> But based on company previously selected -> which field is this?

2. My Services field, needs to show the Terms and Conditions available for the company selected
2.1 Reference: clm_m2m_contract_and_terms
2.2 Field type: Reference

-> what did you start with and where are you stuck

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

@HansellF 

Hope you are doing good.

Did my reply answer your question?

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