CA Service Management

Expand all | Collapse all

Populating user details on Catalog on form Load

  • 1.  Populating user details on Catalog on form Load

    Posted 04-05-2017 10:10 AM

    I am trying to get the cost centre of a user to display when he/she opens a form. 

     

    So my form looks like this

     

     

    There is no script on the form and the values still pull through (on load of the form). 

    I now want to add the cost centre of the contact on load. 

     

     

    So if I make the value of cost center say $(_.user.localeCountry) ..... then the form will load automatically load with "South Africa".

    Where is the _.user stuff defined? Is it in the mdb and if so what is the table name?

     

     

     

     

    I understand that if I use the lookup field then the cost centre can be pulled through, but I want the cost centre to be pulled through on load of the form.  

     

    Where would I use a ca_ReportQuery function? Would it be here?

    Are there any out of the box offerings that use ca_ReportQuery?

     



  • 2.  Re: Populating user details on Catalog on form Load

    Posted 04-05-2017 11:03 AM

    The Cost Center is a field on the Contact, but it's details are stored in a separate table (ca_resource_cost_center)

    All of the data associated with the _.user is stored in the MDB, of course, but it's not in a single table. The Contacts' table is ca_contact, this is where most of the user's data is stored (as value or reference to some other common tables). Some other fields, like the data1 to data7 fields, are taken from the usm_contact_extension table.

    Not all attributes from ca_contact are available on the _.user variable and I think this includes Cost Center. So you'll have to find a way to extract the data through a lookup (query).



  • 3.  Re: Populating user details on Catalog on form Load

    Posted 04-05-2017 11:34 AM

    As i said on the other thread, _.user is not customizable. (As far as i'm aware).

     

    You need to create a report object that brings back the information you want.

     

    You will then call your report object within your form's script with ca_reportQuery.

     

    In my exemple, i have a report object with the following query :

     

    SELECT CNT.last_name, CNT.first_name, CNT.email_address, USPCNT.z_title AS position, CNT.userid,
    FROM mdb.dbo.ca_contact AS CNT

    INNER JOIN mdb.dbo.usp_contact AS USPCNT

       ON USPCNT.contact_uuid = CNT.contact_uuid

    where CNT.userid = '%userid%'

     

     

     

    On my form, when the lookup that brings back the userid of a selected user is completed, i call getData()

    getData: function()
    {
    var userid = ca_fdGetTextFieldValue(ca_fd.formId,'yourTextBoxWithTheUserID');
    ca_reportQuery('yourReportObject', {'userid':userid}, function(rows) { ca_fd.js.writeEmployeeInfo(rows);}, null);
    },

     

    getData will execute the report object with the query i pasted. On success, ca_reportQuery will call an anonymous function (and pass the results set from the query as a parameters), wich will then call a function defined in your script. (writeEmployeeInfo)

     

    writeEmployeeInfo : function(rows)
    {
    if (rows.length>0)
    {
    ca_fdSetTextFieldValue(ca_fd.formId,'txt_info_userid',rows[0]['userid']);
    ca_fdSetTextFieldValue(ca_fd.formId,'txt_info_title',rows[0]['position']);
    ca_fdSetTextFieldValue(ca_fd.formId,'txt_info_email',rows[0]['email_address']);
    ca_fdSetTextFieldValue(ca_fd.formId,'txt_info_first_name',rows[0]['first_name']);
    ca_fdSetTextFieldValue(ca_fd.formId,'txt_info_last_name',rows[0]['last_name']);
    }
    },

     

    WriteEmployeeInfo receives the results set as a parameter. Technically, there is only one user with a specific userid so this is why i do not use a loop to read the results set.

     

    The results set, defined as "rows " in my exemple, is an "array" with named indexes. The name of the indexes are the exact same as the column name in your query. Except that the case of your column name will not be kept.

     

    Hope this helps.