Forum Discussion

Chirag Shah's avatar
Chirag Shah
Copper Contributor
Aug 30, 2018
Solved

Rest API - Fetch Data using POST method and CamlQuery and Lookup Column

Hello,

 

I am trying to get Username(Display name) from YourName field which is Person type field. But When I get result, I get ID as YourNameId. How can I get name rather than Id with using following method because it's mendatory for me to use it.

 

var restUrl = "https://contoso.sharepoint.com/_api/web/lists/GetByTitle('JourneyDetails')/GetItems";
var camlQuery = "<View><ViewFields><FieldRef Name='YourName' /></ViewFields></View>";
axios .post( restURL, { query: { __metadata: { type: "SP.CamlQuery" }, ViewXml: camlQuery } });

 

Update: 02-09-2018

I want to use filter as well

I have 2 more fields. Where I need condition like below

 

$filer= (SuprvisorResponse eq 'Approved') and ((DepartmenResponse ne 'Approved') or (DepartmenResponse ne 'Rejected')))

  • I got the solution. I used the POST method to fetch data from the list

    My actual query is around 384 characters long.

    I think this post can be helpful to anyone who is seeking a solution using the POST method and without the character limit.
    When using $expand all the lookup columns must expand using FieldValuesAsText/ColumnName.

    https://contoso.sharpeoint.com/_api/web/lists/GetByTitle('JourneyDetails')/GetItems?$select=*,FieldValuesAsText/YourName,FieldValuesAsText/Author&$expand=FieldValuesAsText&$filter=SupervisorApprovalStatus eq 'Approved' and TravelDepartmentApprovalStatus ne 'Approved' and TravelDepartmentApprovalStatus ne 'Rejected'

4 Replies

  • Rishi Gupta's avatar
    Rishi Gupta
    Brass Contributor

    Why are you using REST and CAML together. Looking at the query below, you can retrieve the values using REST api itself.

     

    Try using $expand in the REST query to expand the column values. $expand can be used with User/Lookup/Choice fields etc to get the values instead of ID's.

    https://contoso.sharepoint.com/_api/web/lists/GetByTitle('JourneyDetails')/GetItems?$select=*,Author/Title&$expand=Author

     

    • Chirag Shah's avatar
      Chirag Shah
      Copper Contributor

      I want to use filter as well

      I have 2 more fields. Where I need condition like below

       

      $filer= (SuprvisorResponse eq 'Approved') and ((DepartmenResponse ne 'Approved') or (DepartmenResponse ne 'Rejected')))

       

      Problem for me is that when I build query it goes beyond 260 characters limit. I am using Sharepoint Online and there is possibility that I need to add one more filter.

      So problem is getting bigger and bigger.

      So I want solution where there is no limitation for this.

      If you have any workaround please let me know.

      And thank you for earlier reply but it isn't much helpful.

      • Chirag Shah's avatar
        Chirag Shah
        Copper Contributor

        I got the solution. I used the POST method to fetch data from the list

        My actual query is around 384 characters long.

        I think this post can be helpful to anyone who is seeking a solution using the POST method and without the character limit.
        When using $expand all the lookup columns must expand using FieldValuesAsText/ColumnName.

        https://contoso.sharpeoint.com/_api/web/lists/GetByTitle('JourneyDetails')/GetItems?$select=*,FieldValuesAsText/YourName,FieldValuesAsText/Author&$expand=FieldValuesAsText&$filter=SupervisorApprovalStatus eq 'Approved' and TravelDepartmentApprovalStatus ne 'Approved' and TravelDepartmentApprovalStatus ne 'Rejected'

Resources