Need help with Catalog Client Script

Hritik
Tera Expert

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:" 

Hritik_0-1700139116415.png

 

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.

 

  

1 ACCEPTED SOLUTION

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();

 

TaiVu_0-1700209730090.png

 

 

Cheers,

Tai Vu

View solution in original post

14 REPLIES 14

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



 

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 ?

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

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

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();

 

TaiVu_0-1700209730090.png

 

 

Cheers,

Tai Vu