How to Make a Question Dependent Upon Previous Question in Service Catalog

jmiskey
Kilo Sage

We are creating a Service Catalog that has some questions that are dependent upon the answer to the previous question.   For example, we have the following tables in a custom application:

Site: key field is Site Location

Service: key field is Service Name

Site Service Mapping: Table that has two fields (Site and Service), and has a record for each Site/Service that is offered

For example:

Site

Location1

Location2

Location3

Service

Service1

Service2

Service3

Site Service Mapping

Location1     Service2

Location1     Service3

Location2     Service1

Location3     Service1

Location3     Service2

Location3     Service3

So, in my Service Catalog, I have added an Item, and then two Variables to this Item for the two questions.

The first Variable is a Reference type, and asks the person to select their Site from the list.

The second Variable is also a Reference type, and asks the person to select their Service from the Site Service Mapping.   So, basically, what should happen is that after the user selects their Site, the second Variable should be filtered based on that site to only show the Services available for that Site.   For example, if the user selected Location1, it would only show Service2 and Service3 in that second Variable, since those are the only two services offered at Location1.

It looks like this should be fairly easy/straightforward is we were able to take the value selected from the first variable, and use it in the Condition (Reference qual condition) of the second variable.   But we have been unable to figure out the syntax to do that (maybe it is not possible)?   One way we tried was a condition like this:

Site is javascript: g_form.getValue('LocationRequest');

(where LocationRequest is the name of the first variable).

So, the question is, can this be done via this manner, and if not, how do we accomplish this (where we get the answer from the first variable and apply to filter the list for our second variable)?

Thanks

8 REPLIES 8

Vladi1
Kilo Guru

I had similar request and I did it via onChange script. (We use onLoad script to hide "Service" field, so it is visible on "Site" selection only)


onChange script (for your scenario):



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }


  var category = g_form.getValue('site_variable');


  g_form.setDisplay('service_type', true);


  //Clear Request Type


  g_form.clearOptions(' service_type');


  g_form.addOption('service_type', '', '-- None --', 10); //add None to dropdown



  if (category == 'location1'){


  g_form.setDisplay('service_type', true);


  // display options


  g_form.addOption('service_type', 'service_2', 'Service 2', 100);


  g_form.addOption(''service_type', 'service_3', 'Service 3', 200);


   


  }


  else if (category == 'location2'){


  g_form.setDisplay('service_type', true);


  // display options


  g_form.addOption('service_type', 'service_1', 'Service 1', 100);


}



else if (category == 'location3'){


  g_form.setDisplay('service_type', true);


  // display options


  g_form.addOption('service_type', 'service_1', 'Service 1', 100);


  g_form.addOption('service_type', 'service_2', 'Service 2', 200);


  g_form.addOption(''service_type', 'service_3', 'Service 3', 300);


   


  }


}



Our onLoad script to hide Service:



function onLoad() {


  //Type appropriate comment here, and begin script below



  var category = g_form.getValue('site_variable');


  //Clear Request Type


  g_form.clearOptions(' service_type');


  g_form.setDisplay('service_type', false);


}


I don't think that will work.   It really needs to be dynamic.   Our Site Service Mapping tables currently has 472 records in it, and is subject to change at any time as new sites and services are added.


I see; our script is used for defined records.


Deepak Kumar5
Kilo Sage

Hello,


You can populate the Site and service from the mapping table. Make Service Field is dependent of Site.


Based in the Site and service value, You can use the mapping other dependent value.