CA Service Management

Expand all | Collapse all

assign values onload to a lookup field on catalog

Jump to Best Answer
  • 1.  assign values onload to a lookup field on catalog

    Posted 05-24-2016 05:46 AM

    Hi Guys

     

    Does anyone have an example of how I can assign values to a lookup field onload using JavaScript?

     

    This is how I would code this using HTML & javascript, if my lookup field id was FirstName.

         document.getElementById("FirstName").value = x;

     

    Thanks

    Sivu



  • 2.  Re: assign values onload to a lookup field on catalog

    Posted 05-24-2016 09:27 AM

    lookup controls are populated by using the JavaScript attribute named onLookup. Use the pre-defined JavaScript function ca_fdDoFieldLookup(fieldId,reportId) where reportId is the name of a Report Data object you creted in Report Builder (under the Administration tab).



  • 3.  Re: assign values onload to a lookup field on catalog

    Posted 05-24-2016 09:40 AM

    Thanks Linday, is there a way of populating a value on a lookup field before the use clicks the lookup field to trigger the onlookup method or typing a default value on the value property on the lookup field.

    The reason I want to do this is, we have a standard where we include the cost center nomber on our location name, I want to extract the cost center on the loaction name and populate it on a lookup field if the user want to update the cost center

    on this location they would click it and select a different cost center, if it is correct, the would just leave the value and update other fields.

     

    So I want to populate my lookup field onLoad and not onlookup.

     

    Thanks again Lindsay, I hope this makes sence now.



  • 4.  Re: assign values onload to a lookup field on catalog

    Posted 05-24-2016 10:28 AM

    Hi Sivuyile,

    I don't have an easy answer for you as this falls into the "How do I made the tool work the way I wish it would work instead of the way it was designed to work?" realm. In your standard you have re-purposed Location Name into a combo Location/CostCenter Name where Location has a specific Cost Center except in some Requests where it differs.

     

    Here is how I might approach this:

    Add another lookup control on your form (perhaps named "Cost Center Override" that could use a report data object accessing the ca_resource_cost_center table.



  • 5.  Re: assign values onload to a lookup field on catalog
    Best Answer

    Posted 05-24-2016 11:22 AM

    You can set and get value from a lookup with the ca_fdGet and ca_fdSetTextFieldValue

     

    So : ca_fdSetTextFieldValue(formId, "lkp_1", "toto"); wirtes toto in the lkp_1 lookup.

     

    Replace "toto" with the cost center, returned from a ca_reportQuery.



  • 6.  Re: assign values onload to a lookup field on catalog

    Posted 05-26-2016 06:18 AM

    Possq advice worked for me, Do you perhaps know how can do the same this for a select field. Thanks Guys



  • 7.  Re: assign values onload to a lookup field on catalog

    Posted 05-26-2016 08:33 AM

    You cannot set a value to a select field.

     

    You need to Select an options in it using :

    ca_fdSelectOption(formId, _id, name, value)

    or

    ca_fdSelectOptionByIndex(formId, _id, index).

     

    Before selecting a value you need to fetch the data.

     

    There's 2 way.

    ca_fdFetchSelectData(formId, _id)

    Or

    Set the Select field attribute "Eager" to true. It will load the data when the form load instead of when a user click on it.