How to make multiple field references

Arthur Sanchez
Giga Guru

Captura de tela 2024-04-18 151711.pngThe Area field has the options:

ti and seg: IT in the field system: APP, BRM, CAPTA, GPP

SEG in the system field: SMS, IMS, ACS

 

Now the problem is, I need to reference it multiple times, so when the Area field is selected the following are presented in the Service Type field:

 

TI

  1. Configuration
  2. Maintenance
  3. Customization
  4. Installation
  5. Consulting
  6. Backup and Recovery
  7. Training
  8. Request

 

SEG

  1. Configuration
  2. Maintenance
  3. Backup and Recovery
  4. Training
  5. Request
  6. Incident

some fields are repeated and so I am unable to reference them, the first reference I did this way

Captura de tela 2024-04-18 152520.png

 

1 ACCEPTED SOLUTION

Start with creating a new Script Include; for that open module "System Definition ↳ Script Includes":

6.png

 Make sure there is no script include named "Tickets" already (in scope Tickets Register):

7.png

Start the creation of a new record by clicking New.

In the new Script Include record set fields:

  • Name to Tickets
  • Script to
    var Tickets = Class.create();
    
    Tickets.prototype = {
    
    	'initialize': function () {
    		this._dependentValue = typeof dependent_value == 'undefined' ? '' : dependent_value;
    		this._sessionLanguage = 'en'; // gs.getSession().getLanguage();
    	},
    
    	'getSericeTypesForArea': function () {
    		return this._getChoiceList();
    	},
    
    	'type': 'Tickets',
    
    	'_addRecordToChoice': function (glideChoiceList, record) {
    		glideChoiceList.add(record.value, record.label);
    		return glideChoiceList;
    	},
    
    	'_getChoiceList': function () {
    		return new GlideQuery('sys_choice')
    			.where('name', 'x_1316384_tickets_tickets')
    			.where('element', 'service_type')
    			.where('language', this._sessionLanguage)
    			.where('inactive', false)
    			.where('dependent_value', 'CONTAINS', this._dependentValue)
    			.limit(999)
    			.orderBy('sequence')
    			.select(['label', 'value'])
    			.reduce(this._addRecordToChoice, new GlideChoiceList());
    	},
    
    };​

Save the record.

Open up the dictionary record for field "Service type"; switch view to Advanced, otherwise field Attributes will not be displayed:8.png

Modify field Attributes by adding text:

choice_script=new Tickets().getSericeTypesForArea()

 

 

like this:9.png

If there is some text in there already, place a comma between the existing and the new text.
E.g: if it already contains:

edge_encryption_enabled=true

like this:

10.png

the value for Attributes will become:

edge_encryption_enabled=true,choice_script=new Tickets().getSericeTypesForArea()

like this:11.png

That's all there is to it.

Now for each choice for field "Service Type" you have to update field "Dependent value".

In case of "Service Type" choices that should only show for "Area" ti, the value in "Dependent value" should be ti (not ti,seg).

In case of "Service Type" choices that should only show for "Area" seg, the value in "Dependent value" should be seg (not ti,seg).

In case of "Service Type" choices that should show for both "Area" choices, the value in "Dependent value" should be ti,seg as is now.

Of course should you add more "Area" choices, you would just add it to the "Dependent value" as needed.

 

View solution in original post

15 REPLIES 15

Start with creating a new Script Include; for that open module "System Definition ↳ Script Includes":

6.png

 Make sure there is no script include named "Tickets" already (in scope Tickets Register):

7.png

Start the creation of a new record by clicking New.

In the new Script Include record set fields:

  • Name to Tickets
  • Script to
    var Tickets = Class.create();
    
    Tickets.prototype = {
    
    	'initialize': function () {
    		this._dependentValue = typeof dependent_value == 'undefined' ? '' : dependent_value;
    		this._sessionLanguage = 'en'; // gs.getSession().getLanguage();
    	},
    
    	'getSericeTypesForArea': function () {
    		return this._getChoiceList();
    	},
    
    	'type': 'Tickets',
    
    	'_addRecordToChoice': function (glideChoiceList, record) {
    		glideChoiceList.add(record.value, record.label);
    		return glideChoiceList;
    	},
    
    	'_getChoiceList': function () {
    		return new GlideQuery('sys_choice')
    			.where('name', 'x_1316384_tickets_tickets')
    			.where('element', 'service_type')
    			.where('language', this._sessionLanguage)
    			.where('inactive', false)
    			.where('dependent_value', 'CONTAINS', this._dependentValue)
    			.limit(999)
    			.orderBy('sequence')
    			.select(['label', 'value'])
    			.reduce(this._addRecordToChoice, new GlideChoiceList());
    	},
    
    };​

Save the record.

Open up the dictionary record for field "Service type"; switch view to Advanced, otherwise field Attributes will not be displayed:8.png

Modify field Attributes by adding text:

choice_script=new Tickets().getSericeTypesForArea()

 

 

like this:9.png

If there is some text in there already, place a comma between the existing and the new text.
E.g: if it already contains:

edge_encryption_enabled=true

like this:

10.png

the value for Attributes will become:

edge_encryption_enabled=true,choice_script=new Tickets().getSericeTypesForArea()

like this:11.png

That's all there is to it.

Now for each choice for field "Service Type" you have to update field "Dependent value".

In case of "Service Type" choices that should only show for "Area" ti, the value in "Dependent value" should be ti (not ti,seg).

In case of "Service Type" choices that should only show for "Area" seg, the value in "Dependent value" should be seg (not ti,seg).

In case of "Service Type" choices that should show for both "Area" choices, the value in "Dependent value" should be ti,seg as is now.

Of course should you add more "Area" choices, you would just add it to the "Dependent value" as needed.

 

Tabassum22
Tera Guru

Hi @Arthur Sanchez  ,

 

You are on the right track.

For multiple reference you need to make an entry for the the "Service Type" similar to the system field.

For e.g., in incident for we have category, subcategory dependent on category. Also as per your requirement I added a new field Subsubcategory which is also dependent on category as below.

Tabassum22_0-1713482697746.png

For Multiple reference we add the choices in the "Subsubcategory" field similar to the "Subcategory".

Tabassum22_1-1713482795246.pngTabassum22_2-1713482841490.png

Now when we select a category let say "Inquiry/ Help" then the Subcategory and Subsubcategory will be Antivirus which we configured on the choice list dependent on the category filed in your it will be "Area".

Tabassum22_3-1713483012540.png

For the choice list with repeated data you need to create entry for TI and SEG separately.

Hope this helps.

 

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

 

Regards,

Tabassum Sultana

 

 

Arthur Sanchez
Giga Guru
Guys at the beginning, my table and my application:
ArthurSanchez_2-1713543869367.png

my area:

ArthurSanchez_3-1713544007458.pngArthurSanchez_4-1713544025043.png

my system: 

ArthurSanchez_5-1713544059637.pngArthurSanchez_6-1713544072257.png

my Service Type:

ArthurSanchez_7-1713544172130.pngArthurSanchez_8-1713544185210.pngArthurSanchez_9-1713544217052.png


my rule:

TI

  1. Configuration
  2. Maintenance
  3. Customization
  4. Installation
  5. Consulting
  6. Backup and Recovery
  7. Training
  8. Request

 

SEG

  1. Configuration
  2. Maintenance
  3. Backup and Recovery
  4. Training
  5. Request
  6. Incident

I'm creating the entire application through the studio, and I have no idea how to make a reference that follows the rule, because the dependent fields only accept 1 parameter and I'M LOST

 

Defined your Reference field as a "List" type, those accept multiple values.  filter the sys_dictionary table with "Type", "is", "List" to see those OOB fields.

both fields must be choice, so now the 3 fields are choice and the challenge is to be able to make + a reference, but I don't know how