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 Peter,

 

The reference Qualifier is working. 

 

But we have 17 choices. Could you please let me know how can we achieve easily for 17 choices ?

Hi @Hritik,

 

Great that this works. 🙂

You can use the second part of @Tai Vu's reaction. That is exactly the script include, I had in mind. 🙂


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Tai Vu
Kilo Patron
Kilo Patron

 

 

Hi @Hritik 

From where the list choice of the "Please select the region you are in:" is getting data from?

If the Country Name is Choice Text and the Country Code is Choice Value.

Example: Singapore (Text Label) and SGP (Value)

Then, you can simply put this line into the Reference Qualifier.

javascript:"nameSTARTSWITH" + current.variables.please_select_the_region_you_are_in;

 

In the other hands, you can create your own script include to validate with IF Else statement, or do the query to the data table in which you're getting data for the country to get the Country Code.

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

    getCIReferenceQual: function(country_code) {
        var query = '';
        switch (country_code) {
            case "Singapore":
                query = 'nameSTARTSWITHSGP';
                break;
            case "Vietnam":
                query = 'nameSTARTSWITHVN';
				break;
			
			//add more cases, etc

            default:
                query = 'sys_id=-1';
                break;
        }
		return query;
    },

    type: 'CLCatalogItemUtils'
};
javascript:new CLCatalogItemUtils().getCIReferenceQual(current.variables.please_select_the_region_you_are_in.tostring());

 

 Cheers,

Tai Vu

Hi @Tai Vu ,

Thank you.

 

I used the first approach and applied as reference qualifier. But there are also other conditions to be put it:

Hritik_0-1700155129991.png

 

Reference Qualifier only works before javascript;.

 

Could you please let me know if this is the correct way for writing script include ?

 

Reference Qualifier I am trying to work:

 

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; javascript: "nameSTARTSWITH" + current.variables.please_select_the_region_you_are_in

 

it seems the condition is only working before javascript;