CA Service Management

  • 1.  Set a value to a select

    Posted Aug 02, 2017 04:44 PM

    Hello people i have this question

     

     

    i have a form that load some information 

     

     

    when i wrote the userid  and look up the field.  the others fields cédula,localidad  get a value from a Report Query like this

     

    ca_fdSetTextFieldValue(ca_fd.formId, 'lookup_localidad', result[0].localidad);

     

    but this dont happen with the select(yellow)  how can i do this? how can i set a default value to the select

     

    note:the select isn´t static this use a "variable de informe"

     

     

    Thanks for your help



  • 2.  Re: Set a value to a select

    Broadcom Employee
    Posted Aug 03, 2017 04:07 AM

    Good Morning John.
     
    Please check on the below explanation and let me know your findings.
     
    The form is constructed in such a way that (the value of) a designed text-field serves as input for a lookup component.
    Meaning that the content of the look-up list is based on the content of the text-field.
    Which in turn means, that no input is to be entered in the look-up field itself to determine the content of the look-up list.
     
    And it is to say that You can have either or.
    Meaning that when you have the current setting(taking the userid from the pre-populated form-field <form_texffield_id>),
    $({'userid':ca_fdGetTextFieldValue(ca_fd.formId, '<form_texffield_id>')})
    you can open the dropdown list by hitting the down-arrow-icon in the list the corresponding data-query rows will then appear.
     
    OR
     
    You let the look-up content depend on what you type in the look-up itself.
    With this set in the form: $({'<dataquery_where_column>':_val})
    With this setting, you can enter data in the form's look-up component itself to retrieve another list of rows.
     
    To have BOTH is not supported/will not work.
     
    It is supported to enter 'data' in the lookup field and get the corresponding list to be shown.
    In combination with the data object/query: WHERE userid like '%%%user_id%%%'
    Then you can enter (a part of) the userid and the list-content will adapt accordingly.
     
    Kind regards, Louis.



  • 3.  Re: Set a value to a select

    Posted Aug 03, 2017 08:55 AM

    Thanks Louis

     

    Is that I am doing a report query and taking each text field I assign a default with this function Ca_fdSetTextFieldValue (ca_fd.formId, 'lookup_locality', result [0] .locality); The values are correctly assigned to the text and lookup fields but a default value is not assigned to the selection field. I need when I load the form the select field has a default value. how can I do this?



  • 4.  Re: Set a value to a select

    Broadcom Employee
    Posted Aug 03, 2017 09:33 AM

    Good Afternoon John.

     

    That, I am afraid, I have no answer for.

    Perhaps some one else in the community can help you further on this then.

     

    Thanks for your understanding and kind regards, Louis.



  • 5.  Re: Set a value to a select

    Posted Aug 03, 2017 02:42 PM

    thanks for your time bro



  • 6.  Re: Set a value to a select

    Broadcom Employee
    Posted Aug 04, 2017 07:47 AM

    Good Afternoon John.
     
    Sorry, but I couldn't resist further checking on this.
     
    And found the below script-text as a possible answer for you?
     
    ca_fd.js.FormLoad(_.request.id);
    ===================================
    {
     FormLoad: function (requestId){
     
      ca_reportQuery('811b390a5982-166ee919159bc133bef-46581486546611002',
         {'req_id':requestId},
        function(rows)
        {    
         if(rows[0]['ordertype'] == '3'){
          ca_fdHideFields('_generalInfo', ['frameTyp', 'frameChoose', 'frameChoosed', 'frameEcon', 'frameLevInfo']);
         }
         else{
          ca_fd.js.CheckRequestHasCost(requestId);
          ca_fd.js.GetLevInfoFlag(requestId);
          ca_fd.js.getAddressLevels();
          ca_fd.js.GetFrikodLevels();
          ca_fd.js.OrderOneSubscription(requestId);
         }
    ======================================================================
      ca_reportQuery('3afcea41214ad-e0bb3db152ac6628c8-6a811454941440449',
         {'req_id':reqId},
        function(rows)
        {      
         var cost = rows[0]['has_cost'];
         
         if(cost == '1'){ // Beställningen har en kostnad
          ca_fdSetTextFieldValue(ca_fd.formId, 'has_cost', cost);
    ======================================================================
     
    Kind regards, Louis.



  • 7.  Re: Set a value to a select

    Posted Aug 04, 2017 04:51 PM

    If the select field is not populated yet one option could be to use the 'Empty Text' attribute of the select field to display some text. Otherwise you would first need to populate the select and then either select an option via a method like ca_fdSelectOption() or use the 'Selected Index' attribute.

     

    The data object that populates the select field has a variable? If so, where is that data coming from, one of the fields you are setting in the onSuccess function or user input?



  • 8.  Re: Set a value to a select

    Posted Sep 11, 2018 09:25 AM

    @Jason Wolfe, Not  outright horrible but the empty text attrib approach seems a bit hackish (as in we're using a feature in the DOM in a way it wasn't intended to be). It also doesn't pass along the value to the backend. The real problem here is there is no provided way to default a select list value when it is bound to a report data source. This is something that is provided out of the box from just about every major web ui platform I can think of yet it isn't provided in a tool that is supposed to make Form creation simple for Service Catalog? Seems like the feature wasn't completely fleshed out when released. 



  • 9.  Re: Set a value to a select

    Posted Sep 20, 2018 01:11 PM

    I have a solution. If you have a drop down that pulls in for example a list of users from the db and you wanted to default the current user. 

    pass the default user as a second condition into your query. Then sort it based on a match of the userid. 

     

    IE:
    select userid,
    (last_name +', '+first_name+' ('+userid+')') as combo_name,
    (case when userid = '%USERID%' then 1 else 0 end) as def
    from ca_contact
    where userid is not null and userid <> '' and inactive = 0 and last_name <> '' and first_name <> '' and Last_Name+', '+First_Name +' ('+userid+')' like '%LAST_NAME%%'
    order by def desc, combo_name

     

    Now that the targeted user id is at the top of your list all you need to do is default that select by setting selected index to 0. 

    The dropdown now not only searches but it also defaults the current user. 

     

    Cheers!