CA Service Management

 View Only
  • 1.  ca_reportQuery and ca_doFieldLookup

    Posted Dec 05, 2016 05:36 PM

    I have searched and tried to get a better understanding of these two, but I think they can solve my problem.

    I am trying to auto-populate a field based the user filling out the form. So, I already know their _.user.id and it matches to a field in our database. I just don't know how to write the javascript to make it happen, and I think it has something to do with the reportQuery and / or doFieldLookup.

     

    So far I've got this -

     

    ca_reportQuery('requestorInfo', {'userid':_.user.id}, ca_fd.js.onSuccess, ca_fd.js.onFailure);

        onSuccess: function(result) { 
         if (result.length == 1) { 
               ca_fdSetTextFieldValue(ca_fd.formId, 'org_name', 'correctSuccess'); //So I know where I am when the function fires
           } else {
              ca_fdSetTextFieldValue(ca_fd.formId, 'org_name', 'wrongSuccess');
           }
    },

    onFailure: function() { 
        ca_fdSetTextFieldValue(ca_fd.formId, 'org_name', 'Failure');
    },

     

    What I need is to match _.user.id with userid (found in requestorInfo) and the populate 'org_name' with the info found in a table also from requestorInfo.

     

    I have a feeling I am very close, but oh so far away.



  • 2.  Re: ca_reportQuery and ca_doFieldLookup

    Broadcom Employee
    Posted Dec 06, 2016 02:15 AM

    Good Morning Stephen.

     

    The following is an example to get this working.
     
    In sc/admin/report builder, create a data object.
    type     = query
    id       = catalog_contact_list
    database = mdb
    table    = ca_contact
    fields   = userid,first_name,last_name
    query    = SELECT userid,first_name,last_name
               FROM ca_contact
               WHERE upper(userid) like  upper('%STRING%%%')
     
    In SC/Catalog/Forms, create a form with:
    A: The Lookup component on the form:
    _id = userid
    onLookup= ca_fdDoFieldLookup('userid','catalog_contact_list')
     
    NOTE: userid is the first field of the data object fields.
          id-value is the id of the data object
     
    B: The 'text field' component on the form is the field to be filled with data from lookup:
    _id = first_name
    _id = last_name
    The value for '_id' must be equal to the field in the data object.
    And will then be automatically populated when the query executes.
    E.G. for another text field on the form, to be populated with the contact's first_name (as in the query-text),
    the _id of that field must/should be first_name too.
     
    Does this answer your question? And help you further on this?

    PS.
    When you change the query into:
    query =
    SELECT userid,first_name as firstname,last_name as lastname
    FROM ca_contact
    WHERE upper(userid) like  upper('%STRING%%%')

    Then the _id of th fields on the form should be firstname and lastname.
    Equal to the ones that youuse in the 'as' clause in the query-text.

     

    Thanks and kind regards, Louis.



  • 3.  Re: ca_reportQuery and ca_doFieldLookup

    Posted Dec 06, 2016 09:36 AM

    As per Louis said, you need to have your report object ready.

     

    Then you can use ca_reportQuery.

     

    It returns an array of rows. You can access column by name (sql query column name) or index.

     

    If you know that your report object always return only one row, feel free to do :

    ca_reportQuery('requestorInfo', {'userid':_.user.id}, ca_fd.js.onSuccess, ca_fd.js.onFailure);

        onSuccess: function(result) { 
         if (result.length == 1) { 
               ca_fdSetTextFieldValue(ca_fd.formId, 'org_name', result[0]['org_name']); // <-- See? result[rowIndex][columnName]
           } else {
              ca_fdSetTextFieldValue(ca_fd.formId, 'org_name', 'wrongSuccess');
           }
    },

    onFailure: function() { 
        ca_fdSetTextFieldValue(ca_fd.formId, 'org_name', 'Failure');
    },

     

    My example assumes that your report object gets the userid and the org_name