CA Service Management

Expand all | Collapse all

Report Data Objects and Table Components - The Dynamic Link

Jump to Best Answer
  • 1.  Report Data Objects and Table Components - The Dynamic Link

    Posted 02-07-2017 06:11 AM

    Hi all,

     

    This question pertains to CA Service Catalog, in relation to the population of a table component using a report data object, where the report data object would return data based on the userID $(_.user.id) of the logged-in user, dynamically.

     

    For example the user would want to set their availability on particular CA Service Desk groups that they are part of.

     

    How would I go about doing this?

     

    PS: I haven't a clue how to use the Report/Plug-in Variables.

     

    Thanks,

     

    Mo



  • 2.  Re: Report Data Objects and Table Components - The Dynamic Link

    Posted 02-07-2017 10:14 AM

    Good Afternoon Muhammad.

     

    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 you use in the 'as' clause in the query-text.

     

    Thanks and kind regards, Louis van Amelsfort.



  • 3.  Re: Report Data Objects and Table Components - The Dynamic Link
    Best Answer

    Posted 02-07-2017 10:15 AM

    Good Afternoon Mhuhammad.

     

    And another example is related to a (form)script.:

     

    Populate several textfields based on the results of a reportQuery that uses input from a select field.

    The form:
    =========
    form id   = form_1
    select id = userids (displays all available userids.The user selects one.)
    onChange  = ca_fd.js.onChangeUserid();

    Report/Plug-in Variabel = $({'user_ids':ca_fdGetSelectedOptionValues(ca_fd.formId,'userids')[0]})
    Report/Plug-in Id       = 9446bcf476c836e9439a91592ae373a1-70e31482916835192
    textfield id            = email_addr (Autopopulate the email address of the selected user.)
    textfield 2 id          = pnumber (Autopopulate the phone number of the selected user.)

    Data object:
    ============
    A data object populates the selectbox with all available userids with the following query:
    id   : 9446bcf476c836e9439a91592ae373a1-70e31482916835192
    table: ca_contact
    Query: select userid as id, userid, email_address, pri_phone_number from ca_contact where userid like '%user_ids%%%'
    a runtime variable user_ids has been created, containing a string value.

    The script created locally for the form:
    ========================================
    {
    onChangeUserid : function() {
     ca_fd.js.setInfo();
     },
    setInfo : function() {
     var user_ids = {value:ca_fdGetSelectedOptionValues(ca_fd.formId, 'userids')};
     console.log(user_ids.value); // returns an array containing the one userid specified in the selectbox.
     ca_reportQuery('9446bcf476c836e9439a91592ae373a1-70e31482916835192', {'user_ids_report_var':user_ids.value}, ca_fd.js.onSuccess, ca_fd.js.onFailure);

    },

    onSuccess : function(result) {
     if (result.length == 1) {
     console.log('success');
     console.log(result[0]); // by setting (result > 1) above, I can see that this line of code prints an array containing all available objects, not just the one selected.
     ca_fdSetTextFieldValue(ca_fd.formId, 'email_addr', result[0].email_address);
     }
     else {
     ca_fdSetTextFieldValue(ca_fd.formId, 'email_addr', 'Cannot find user details');
     console.log(result);

    }
     },
     onFailure : function(){
     ca_fdSetTextFieldValue(ca_fd.formId, 'email_address', 'Failed');
     },
    }

     

    Kind regards, Louis van Amelsfort.



  • 4.  Re: Report Data Objects and Table Components - The Dynamic Link

    Posted 02-07-2017 11:06 AM

    Thanks Louis_van_Amelsfort. I'll try both your recommendations on Thursday when I'm back at the office.    



  • 5.  Re: Report Data Objects and Table Components - The Dynamic Link

    Posted 02-09-2017 04:41 AM

    Hi Louis_van_Amelsfort

     

    Thank you so much for your assistance.

     

    The code works perfectly with the table element when you tie it in with the information in this document.

     

    Kind regards,

    Mo