Restricting Reference Field Choices

ndejoya
Tera Contributor

Hello! Just had a question I was hoping to get some guidance on as I am relatively new to the ServiceNow environment.

 

The Profit Center field references a Profit Center table

The Fund field references a different table that includes Profit Centers

Both fields are pre-populated

 

What I'm wondering is if there is a way to restrict the Fund field choices to only show Funds that are related to that specific Profit Center populated? Also, when the form is in a specific status, the Fund field should be cleared out and require that new selection. So I was also wondering how I would go about doing that as well. Thank you for your time! 

 

ref q.PNG

1 ACCEPTED SOLUTION

What exactly is meant by status field. Is it a field.
If Yes,

You can write a on change client script to clear the value.

Navigate to Client scripts:
Select new,

Table: Select the table

Type : On Change
Field name: SELECT THE STATUS FIELD

Write the below script



Hope this helps. Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

View solution in original post

7 REPLIES 7

Najmuddin Mohd
Mega Sage

Hi @ndejoya ,

For this requirement, you need to write a advanced reference qualifier which calls a script include with input Profit center. (You pass the value of the profit center to the script Include.)
In script include,
you will query the fund table filtering the profit center.
While you have those records, push those records sys_id in an array and return the array.

If this helps you kindly mark it as Helpful and Accept the solution.

Regards,
Najmuddin.

Hello! Thank you for your response, do you know how this advanced reference qualifier and script include would look? I have not worked with that yet as I am new to the environment. Thank you for your time!

 

Hi @ndejoya ,
Navigate to Script Includes > Create New.
Check box: Client callable
Name: Fund

Something similar to this.

Script Include: Fund
write the below script.

 

 

 

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

fundValues: function(profit) {
var array = [];
var gr = new GlideRecord(TABLE_NAME_OF_PROFIT); 
gr.addQuery('VARIABLE_NAME_THAT_H0LDS_PROFIT_VALUE', profit);
gr.query();

while (gr.next()) {
array.push(gr.getValue('sys_id')); // get the sys_id of the records.
}

return array; 
},

type: 'Fund'
};

 

 

 


Advance Reference Qualifier:

Now, right click on the Fund field, configure dictionary,
Then in the related links, click Advance View.

In the Reference Specification section,
Select Advance,
In the Reference qual:

NajmuddinMohd_0-1726685560940.png

NajmuddinMohd_1-1726685572525.png

NajmuddinMohd_2-1726685590661.png

 

 

 



Hope this helps.
Regards,
Najmuddin.




 

ndejoya
Tera Contributor

Wow, this has been very helpful. Thank you! My last question would be, since the Fund value is prepopulated on the form, what steps do I take to have that value cleared out when the form is set to a different status?