- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 11:26 AM
The 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
- Configuration
- Maintenance
- Customization
- Installation
- Consulting
- Backup and Recovery
- Training
- Request
SEG
- Configuration
- Maintenance
- Backup and Recovery
- Training
- Request
- Incident
some fields are repeated and so I am unable to reference them, the first reference I did this way
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 05:45 PM
Start with creating a new Script Include; for that open module "System Definition ↳ Script Includes":
Make sure there is no script include named "Tickets" already (in scope Tickets Register):
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:
Modify field Attributes by adding text:
choice_script=new Tickets().getSericeTypesForArea()
like this:
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:
the value for Attributes will become:
edge_encryption_enabled=true,choice_script=new Tickets().getSericeTypesForArea()
like this:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 04:06 PM - edited 04-18-2024 04:09 PM
You can use dictionary attribute choice_script - which is kinda' like a reference qualifier for choice lists.
I don't call it an equivalent because in a reference qualifier one has access to the whole current record, but in a choice script one has access only to global variable dependent_value.
That said here's how you can do it:
- Make dependent_value a list (of dependent choices, of course):
- Modify script include global.Incident by including following functions - there might already be stuff in there, in which case you can't just replace the contents, you need to mix in the new parts:
var Incident = Class.create(); Incident.prototype = Object.extendsObject(IncidentSNC, { 'initialize': function (incidentGr) { IncidentSNC.prototype.initialize.call(this, incidentGr); this._u_dependentValue = typeof dependent_value == 'undefined' ? '' : dependent_value; this._u_sessionLanguage = gs.getSession().getLanguage(); }, 'u_getSericeTypesForArea': function () { return this._u_getEmptyList() || this._u_getLoadedList(); }, 'type': 'Incident', '_u_addRecordToChoice': function (glideChoiceList, record) { glideChoiceList.add(record.value, record.label); return glideChoiceList; }, '_u_getEmptyList': function () { if (this._u_dependentValue == '') return new GlideChoiceList(); }, '_u_getLoadedList': function () { return new GlideQuery('sys_choice') .where('name', 'incident') .where('element', 'u_service_type') .where('language', this._u_sessionLanguage) .where('inactive', false) .where('dependent_value', 'CONTAINS', this._u_dependentValue) .limit(999) .orderBy('sequence') .select(['label', 'value']) .reduce(this._u_addRecordToChoice, new GlideChoiceList()); }, });
Note that as is, this will show no choices in lists!
If you want all choices to be shown when no dependency is selected (e.g. in lists) you need to modify function u_getSericeTypesForArea to be:'u_getSericeTypesForArea': function () { return this._u_getLoadedList(); },
Also I'm assuming you will have the list defined for all available languages.
If you don't do that and only defined the list for language code en, you need to modify the query to filter language not to the session language, but to code en.
I'm also assuming the name of the field is u_service_type; if this is not the case, adjust accordingly.
Another assumption is that the list is defined for table incident; if this is not the case, adjust accordingly. - Add the dictionary attribute to field "Service type":
or, in text:
choice_script=new global.Incident().u_getSericeTypesForArea()
I suppose that's about it.
Here's how it looks at my end with a prototype I have created:
- when no area is selected:
- when SEG is selected:
- when TI is selected:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 06:01 AM - edited 04-19-2024 06:03 AM
Bro, it seems like your idea works, the problem is that I don't understand how to make it work
my service type:
my table is: x_1316384_tickets_tickets
I already put the values of dependent fields in my service type, now what?
My application looks like this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 06:14 AM
You need to add the attribute (into field Attribute).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 07:23 AM
Dude give me a step by step guide on how to do this, I don't even know where to put this script and how to call it