- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 04:56 AM
Hi Community,
I need help in developing client script.
Please consider below scenario:
When I select "Singapore" as a choice from the field "Please select the region you are in:"
Then the records in field "Please select the Service you are having issue with:" must only start from SGP.
The field "Please select the Service you are having issue with:" is a Reference field to cmdb_ci table.
Please help me construct a On Change Client Script that modifies the data i.e starts with SGP .
Thanks in Advance,
Hritik.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 12:25 AM - edited 11-17-2023 12:29 AM
Hi @Hritik
Okay there you go! 😋
javascript:"operational_status=1^sys_class_name=cmdb_ci_appl^ORsys_class_name=cmdb_ci_service^ORsys_class_name=cmdb_ci_service_technical^ORsys_class_name=cmdb_ci_service_business^nameSTARTSWITH" + current.variables.please_select_the_region_you_are_in.toString();
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 10:19 PM
Hi @Hritik
For better maintenance, let's put it into a function from a script include, then you can call that function from the reference qualifier.
You may also need to handle when the None option is selected.
var CLCatalogItemUtils = Class.create();
CLCatalogItemUtils.prototype = {
initialize: function() {},
getCIReferenceQual: function(country_code) {
if(gs.nil(country_code)){
return 'sys_id=-1'; //return empty when none
}
var query = 'operational_status=1^sys_class_name=cmdb_ci_appl^ORsys_class_name=cmdb_ci_service^ORsys_class_name=cmdb_ci_service_technical^ORsys_class_name=cmdb_ci_service_business^nameSTARTSWITHS' + country_code;
return query;
},
type: 'CLCatalogItemUtils'
};
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 11:45 PM
Hi @Tai Vu
It is still not working.
I used the script include you shared:
SI:
var CLCatalogItemUtils = Class.create();
CLCatalogItemUtils.prototype = {
initialize: function() {
},
getCIReferenceQual: function(country_code) {
var query = '';
switch (country_code) {
case "SGP":
query = 'nameSTARTSWITHSGP';
break;
case "Australia/ New Zealand":
query = 'nameSTARTSWITHANZ';
break;
case "Austria":
query = 'nameSTARTSWITHAT';
break;
case "BEL":
query = 'nameSTARTSWITHBEL';
break;
case "Canada":
query = 'nameSTARTSWITHCAN';
break;
//add more cases, etc
default:
query = 'sys_id=-1';
break;
}
return query;
},
type: 'CLCatalogItemUtils'
};
Reference Qualifier:
javascript: new CLCatalogItemUtils().getCIReferenceQual(current.variables.please_select_the_region_you_are_in.tostring());
It shows 0 records when tested.
Could you please let me know the mistake here ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 12:09 AM
Hi @Hritik
Changes this line.
from
javascript:new CLCatalogItemUtils().getCIReferenceQual(current.variables.please_select_the_region_you_are_in.tostring());
to
javascript:new CLCatalogItemUtils().getCIReferenceQual(current.variables.please_select_the_region_you_are_in.toString());
Make sure to change this syntax ":" to ":" as well.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 12:14 AM
Hi @Tai Vu
Thank you for the reponse.
Can you please help to work this only from reference qualifier ?
I have these two main query:
First:
operational_status=1^sys_class_name=cmdb_ci_appl^ORsys_class_name=cmdb_ci_service^ORsys_class_name=cmdb_ci_service_technical^ORsys_class_name=cmdb_ci_service_business;
Second:
javascript: "nameSTARTSWITH" + current.variables.please_select_the_region_you_are_in
Could you please help me to write correct syntax for this ? I have tried multiple way but they doesn't work when added togheter?
Altough they do work individually.
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 12:25 AM - edited 11-17-2023 12:29 AM
Hi @Hritik
Okay there you go! 😋
javascript:"operational_status=1^sys_class_name=cmdb_ci_appl^ORsys_class_name=cmdb_ci_service^ORsys_class_name=cmdb_ci_service_technical^ORsys_class_name=cmdb_ci_service_business^nameSTARTSWITH" + current.variables.please_select_the_region_you_are_in.toString();
Cheers,
Tai Vu