none
can we retrive other fields value using look up RRS feed

  • Question

  • Greetings,

    have designed look up column which works fine.

    Problem:

    I want to retrive other fields value using look up Like

    I have list Dept contains 3 fields 

    ID,DeptName,Deptalias

    List 2 name DeptDetils contains Lookup of list "Dept"  like ID,DeptName ( Look up ) 

    Solution Required:

    Using this look up , how can I get DeptAlias values ??

    Thanks

    Wednesday, July 1, 2020 11:32 AM

All replies

  • Hi,

    Yes, we could get look up value.

    Rest demo:

    /_api/web/lists/getbytitle('DeptDetils')/items?$select=Title, DeptName/DeptAlias&$expand=DeptName 

    Best regards,

    Amos


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    Thursday, July 2, 2020 3:03 AM
  • i am writing code on C# not rest api
    Friday, July 3, 2020 12:04 PM
  • Hi,

    Demo:

     ClientContext ctx = new ClientContext("http://sp");
    
                    List list = ctx.Web.Lists.GetByTitle("test");
                    ListItem item = list.GetItemById(1);
                    var field = list.Fields.GetByInternalNameOrTitle("look");
                    var lookupField = ctx.CastTo<FieldLookup>(field);
                    ctx.Load(lookupField);
                    ctx.Load(item);
                    ctx.ExecuteQuery();
                    
                    FieldLookupValue lookup = item["look"] as FieldLookupValue;
                    var lookupListId = new Guid(lookupField.LookupList); //returns associated list id
                                                                         //Retrieve associated List
                    var lookupList = ctx.Web.Lists.GetById(lookupListId);
                    var lookItem=lookupList.GetItemById(lookup.LookupId);
                    ctx.Load(lookItem);
                    ctx.ExecuteQuery();
                    Console.WriteLine(lookItem["test"]);

    Best Regards,

    Amos


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, July 6, 2020 7:45 AM
  • Thanks for response, but hard luck.

    as I mentioned above , having 3 fields on list like ( Parent list name is Deprtmentlist )

    ID,DeptName,Deptalias.

    and on other list , which is list 2

    List 2 name is: "DeptDetils"  which contains Lookup of "Deprtmentlist"  like ID,DeptName ( Look up ) .

    how to pick "deptalias " fields with look up fields of ID "Deprtmentlist" directly.

    I know to pick ID of lookup then pass to "departmentlist " to get relevant fields like deptalias.

    can we do that directly , as  we can pick Deptname ,no need call "Deprtmentlist" by passing ID to pick "DeptName"

    Hope you get point.

    Thanks

    Tuesday, July 7, 2020 7:25 AM
  • Hi,

    You could call SharePoint Rest API using c#.

    Demo

    HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create("http://sp/_api/web/lists/getbytitle('DeptDetils')/items?$select=Title, DeptName/DeptAlias&$expand=DeptName ");
    
                    endpointRequest.Method = "GET";
    
                    endpointRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
    
                   
    
                    endpointRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
                    HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
    
                    try
    
                    {
    
                        WebResponse webResponse = endpointRequest.GetResponse();
    
                        Stream webStream = webResponse.GetResponseStream();
    
                        StreamReader responseReader = new StreamReader(webStream);
    
                        string response = responseReader.ReadToEnd();//results
    
                        responseReader.Close();
    
                        Console.ReadLine();
    
                    }
    
                    catch (Exception e)
    
                    {
    
                        Console.Out.WriteLine(e.Message); Console.ReadLine();
    
                    }

    Best regards,

    Amos


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 7, 2020 9:59 AM
  • Hi,

    Would you please provide us with an update on the status of your issue?

    If my reply helped you, you could mark it as the answer,so it may help other community members find the helpful information quickly.

    This “SharePoint 2013 - Development and Programming” Forum will be migrating to a new home on Microsoft Q&A, please refer to this sticky post for more details.

    Best Regards,

    Amos


    "SharePoint" forums will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "SharePoint" forums' new home on Microsoft Q&A !

    Thursday, July 16, 2020 8:17 AM