Populate a value in a variable based on 3 variables in Catalog value

Avee90
Tera Contributor

Hello Folks,
   

         I've a catalog item, in that there are four fields where 4rth field will depend on the first 3 fields. Based on the combinations values from 3 fields then only 4 field should populate. 4th field have more than 100 choice so we are not going with addOption. I've decided to use a custom table.
The custom table has fields to give the input. I'm just trying to store the combinations of 3 fields and 4rth field to populate. 
Is there any possibility to do with Script Include to populate 4rth field.
I'm adding the custom table field and catalog item form in the attatchents as a reference. Please help me with the scriptinclude

Thanks in advance.

3 REPLIES 3

_Gaurav
Kilo Sage

Hi @Avee90 
Yes, this is possible, but as per my understanding, you have to write 3 onChange client scripts because the user can change any field value, and based on that the group should populate.

 

Procedure:

Pass all these 3 values to your script include

Make the correct format like Country + State + Location

Glide to the custom table and find the specific record

Return the group value.

In the CS you'll get the group value in the answer variable

Set the answer variable value to the group field.

 

Note: It would be very helpful for you to change the custom table field type to the same as the catalog item field type. It will increase the correctness of the logic.

 

Please mark helpful and accept as a solution if this resolves your query

Thanks!

Avee90
Tera Contributor

Hello Gaurav,

      Thank you for you response my question. Do you have any sample script for Script include to get the concatenated values. I'm actually new to scripting

Thanks,
Naveen

Hi @Avee90 
This is not the exact script but yes this might be helpful for you to achieve the functionality.
The below script will run when you choose the location field value, make the the above 2 fields have values.

onChange Client Script (select the Location variable in the variable field)

var ga = new GlideAjax(‘scriptincludename’); //Pass the script include name

ga.addParam('sysparm_name',method_name’); //Pass the method name

ga.addParam('sysparm_country',g_form.getValue(‘country’)); //Getting value of country field

ga.addParam('sysparm_state',g_form.getValue(‘state’)); // Getting value of state field

ga.addParam('sysparm_location',newValue); //Getting value of location field

ga.getXML(setGroup);

 

function setGroup (response) { 

   var answer = response.responseXML.documentElement.getAttribute("answer");

    g_form.setValue(‘group’,answer); //Setting the value of group field 

}

 

Script Include

getGroupValue : function(){

var country = this.getParameter(‘sysparm_country’);

var state = this.getParameter(‘sysparm_state’);

var location = this.getParameter(‘sysparm_location’);

var mergedValue = country+’ + ’+state+’ + ’+location; //Concatinationg all the 3 values

var grTable = new GlideRecord(‘custom_table_name’); //Pass the custom table name

grTable.addQuery(‘value_1’,mergedValue);

grTable.query();

if(grTable.next()){

return gr.value_2; // returning the value of group stored in value 2 variable

}

}

 

Make sure all the backend values and field values are written properly to make it happen as all these fields are choice type.


Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks!