Preselect Select Field via Report Query
search cancel

Preselect Select Field via Report Query

book

Article ID: 390626

calendar_today

Updated On: 03-12-2025

Products

CA Service Catalog

Issue/Introduction

In a Service Catalog Form, customer has a select-field using a defined query.

When opening the form for a new request, the select-field should be preselected with the logged in user.

However, the select-field is not preselected.

The query itself works fine also via the Service Catalog UI and the additional text field prefilled with $(_.user.id) shows the correct value.

Environment

CA Service Catalog 17.3 and 17.4

All Supported Operating Systems

Resolution

Syntax to pass the query variable is like $({'<variable_name>':'value'})

For example, for OOTB report data object 'catalog__content_country_list'

Query : SELECT id,name FROM ca_country WHERE (ca_country.name like N'%%%STRING%%%')

Select Box Parameters will be

Report/Plug-in Id: catalog__content_country_list

Report/Plug-in Variables: $({'STRING':_.user.location.country})

Additional Information

A.  How to default selection with the logged in user

1.  Remove any "where" clause from the report object to load all the data into select field

For example, SELECT userid,last_name FROM ca_contact

2.  Remove "Report/Plug-in Variables" attribute of select field if any

3.  Set "Eager" attribute of select field to "true"

4.  Set "onLoad" attribute of select field to "ca_fd.js.loadDefaultUser();"

5.  Add form script as below ('sel_1' to be replaced with select field id)

{
  loadDefaultUser: function(){
    ca_fdSelectOption(ca_fd.formId, 'sel_1', _.user.lastName, _.user.id);
  }
}

6.  Save form and test in request page

After the form is loaded, default selection should be shown in a second or two.

B.  When I want to use _.user. in external script because I do not want to replicate code in different forms of different offerings.  What can I try in custom_form_example.js where _.user seems not to be defined?  Can I give _.user in the onload script-call as parameter and use it there with the known parameters?

_.user. should work in custom_form_lib.js as well, and yes you can pass as arguments too as below

onLoad:  loadDefaultUser(ca_fd.formId,'sel_1',_.user.commonName,_.user.id);

Note: The function call does not contain ca_fd.js prefix if the function is defined in the custom js

custom_form_lib.js:

function loadDefaultUser(formId,fieldId, cname, id){
    ca_fdSelectOption(formId, fieldId,cname+'('+id+')', id);
}