[Vtigercrm-developers] How to use server api to get information about assigned user, like their name?

nilay khatri nilay.spartan at gmail.com
Sun Apr 5 10:38:59 GMT 2020


Hi Sutharsan,

Thanks.


To register a new webservice operation please use the vtlib functions
rather then directly doing database query.

The problem here is to fetch Users data as non-admin user.

I clubbed this with reference fields due to similarity. In the end we need
related record's data.

So if you have authorized as non-admin user you can never get the name /
details of assigned to user/ group.


As such I mentioned the approaches that we thought of.

We went ahead with the option 1. and added a new parameter to query and
retrieve api. If set as 1, it return the reference records data as a
sub-array. If it is users module and authorized user is a non-admin user
then we expand to only few fields.







On Sun, Apr 5, 2020, 3:17 PM Sutharsan J <ajstharsan at gmail.com> wrote:

> Hi Nilay
>
> You can use multiple queries for each reference field returned from main
> module response.  If you want to know how to write a custom web service
> method check below steps
>
>    1.  Add New file under "Include/Webservices/". Example if new method
>    name is "retrieveproduct", file name should be RetrievProduct.php
>    2. Add function"vtws_retrieveproduct" under above file and write
>    required code
>    3. Add a record in table vtiger_ws_operations and update sequence at
>    vtiger_ws_operation_seq.
>    4. Also add parameters in table vtiger_ws_operation_parameters. Example
>
>>    *INSERT INTO `vtiger_ws_operation` (`operationid`, `name`,
>>    `handler_path`, `handler_method`, `type`, `prelogin`) VALUES ('34',
>>    'retrieve', 'include/Webservices/Retrieve.php', 'vtws_retrieve', 'GET',
>>    '0');*
>>
>>    *UPDATE `vtiger_ws_operation_seq` SET `id` = '34' WHERE `id` = '33';*
>>
>>    *INSERT INTO `vtiger_ws_operation_parameters` (`operationid`, `name`,
>>    `type`, `sequence`) VALUES ('34', 'id', 'String', '1'; *
>
>    5. *To enable mobile api, add a similiar file and function under
>    "modules/Mobile/api/ws". Example "FetchProduct.php".*
>    6. *Add the class like "Mobile_WS_FetchProduct" 5. Add an entry of
>    above class under "modules/Mobile/api.php". Example
>    'fetchRecordsWithGrouping' => array('file' =>
>    '/api/ws/FetchRecordsWithGrouping.php', 'class' =>
>    'Mobile_WS_FetchRecordsWithGrouping');*
>
>
>
> below is a custom web service function which get all module language
> strings
> https://github.com/radus28/vtig_ws_language
>
> Thanks
> Sutharsan Jeganathan
>
> On Sat, Apr 4, 2020 at 4:31 PM nilay khatri <nilay.spartan at gmail.com>
> wrote:
>
>> Oh sorry, I replied too fast.
>>
>> You have asked to get the user's info base don the assigned user id.
>>
>> While resolving this for automateCRM, we though about 3 approaches:
>>
>> 1. add another parameter to operations such as retrieve, query, if set as
>> true, then it also returns the related record's (reference/owner) data as a
>> sub array. For users and groups it returns only basic info like name,role,
>> calendar settings etc.
>> - This might cause some performance issues if you have many reference
>> fields
>>
>> 2. for all reference and owner fields always return the display value
>> along with the record id.
>> - good approach if you need only display labels. But might cause
>> compatibility issues with existing apps consuming the existing rest api.
>>
>> 3. implement another webservice operation which would return basic info
>> of all the accessible users/group to the currently logged in user.
>> - might cause issues if you are caching the fetched data, as the
>> accessible users/group can change anytime. But, still you need to make
>> separate calls to fetch label values for reference fields and the custom
>> api anyways
>>
>>
>>
>>
>>
>> On Sat, Apr 4, 2020 at 3:56 PM nilay khatri <nilay.spartan at gmail.com>
>> wrote:
>>
>>> Hi Alan,
>>>
>>> We have implemented me api for the same.
>>>
>>> I guess I have a merge request on git as well for the same.
>>>
>>> Will share more details in sometime.
>>>
>>> On Fri, Apr 3, 2020, 7:50 PM Alan Lord <alanslists at gmail.com> wrote:
>>>
>>>> I'm working on another idea for a module and to work within the rules
>>>> of
>>>> the Marketplace I am trying to use the server API vtws_retrieve to get
>>>> information about the assigned_user_id of a record to display in a
>>>> different environment. I am using vtws_retrieve to get the data from
>>>> the
>>>> original record, but I can't do the same to get "display" data
>>>> regarding
>>>> the assigned user...
>>>>
>>>> If I try something like:
>>>>
>>>> > vtws_retrieve('19x22', $current_user)
>>>>
>>>> And I am that current user, e.g. id 22, then the call fails with
>>>> "Permission to perform the operation is denied"
>>>>
>>>> All I actually want is to get some of the basic data like the display
>>>> name (first_name + ' ' + last_name) and maybe their email/phone etc...
>>>>
>>>> But this seems to be not possible.
>>>>
>>>> What is the correct way to do this? I could, or course use a different
>>>> user to make these calls i.e. Users::getActiveAdminUser(), but I am not
>>>> sure if that would be permitted by the marketplace rules.
>>>>
>>>> PS: Also in many ways, it's a lot easier using things like the record
>>>> models as they have built in methods like getDisplayName()...
>>>>
>>>> _______________________________________________
>>>> http://www.vtiger.com/
>>>>
>>> _______________________________________________
>> http://www.vtiger.com/
>
>
>
> --
>
>
>
>
>
>
>
>
>
> *Development Manager Radus28 Software Solution [image: Radus28 Software
> Solution] 123, Level 2, Mc Larens Building Baudhaloka Mw. Colombo 04 Sri
> Lanka M : +94773795291 E  : sutharsan at radus28.com <sutharsan at radus28.com> W
> : www.radus28.com <http://www.radus28.com>*
> _______________________________________________
> http://www.vtiger.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20200405/b4661501/attachment.html>


More information about the vtigercrm-developers mailing list