locked
Custom Lookup Setting Problem using CRM 2016 Web API RRS feed

  • Question

  • I have custom entity name Expense. On save of Expense creating new record of same entity but code alert "bad reqest" while setting lookup of contact.

    without lookup code is running ok but problem while setting lookup of contact

    I tries to set lookup on Account, Opportunity it is running ok only built in lookup set but not set custom lookup.

    How to setup custom lookup anybody set custom lookup plz help me.

    function createNewExpense() { var entity = {};

    entity.new_name = "Test Expense 1"; entity["new_expcontact@odata.bind"] = "/contacts(C17F100D-5-E611-80E7-5065F38B6601)"; var req = new XMLHttpRequest(); req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/new_expenses", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 204) { var uri = this.getResponseHeader("OData-EntityId"); var regExp = /\(([^)]+)\)/; var matches = regExp.exec(uri); var newEntityId = matches[1]; } else { alert(this.statusText); } } }; req.send(JSON.stringify(entity)); }



    Muhammad Sohail








    • Edited by sohail450 Friday, August 19, 2016 11:16 AM
    Thursday, August 18, 2016 9:29 AM

Answers

  • Hi Sohail,
     
    We have faced this issue while setting the custom lookup on an entity.
     
    You may refer the comments in this blog which describes same issue.
     
     
    Hope this helps to resolve your issue.
     

    Thanks!

    Sam



    Inogic | Blog | news@inogic.com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by sohail450 Monday, August 22, 2016 11:09 AM
    Saturday, August 20, 2016 5:53 AM
  • Thanks Sam,

    Yes I resolve my issue using your comment in blog as

    Step 1 : Goto Cutomization  Developer Resource.

    Step 2 : Click to “Download Odata Metadata” link and Download the same.

    Step 3 : Once Download, open it and find out name of lookup attribute (“new_xxxxxx”) and check its casing.

    Step 4 : Verify it with the value which you are setting in the code it should be same.

    Actually for custom lookup Odata Keep first letter of lookup attribute  capital so in my case i use new_Expcontact  instead of new_expcontact.

    but one thing not considering new Web API contains all attributes in small case but why only lookup attribute first letter Capital.

    it confusing very much.


    Muhammad Sohail

    • Marked as answer by sohail450 Monday, August 22, 2016 11:10 AM
    Monday, August 22, 2016 11:08 AM

All replies

  • Hi Sohail,
     
    We have faced this issue while setting the custom lookup on an entity.
     
    You may refer the comments in this blog which describes same issue.
     
     
    Hope this helps to resolve your issue.
     

    Thanks!

    Sam



    Inogic | Blog | news@inogic.com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by sohail450 Monday, August 22, 2016 11:09 AM
    Saturday, August 20, 2016 5:53 AM
  • Please check the GUID for contact. It seems to be in wrong format at first look


    Ramanathan Rajendran MCTS - Dynamics CRM

    Sunday, August 21, 2016 8:33 AM
  • Thanks Sam,

    Yes I resolve my issue using your comment in blog as

    Step 1 : Goto Cutomization  Developer Resource.

    Step 2 : Click to “Download Odata Metadata” link and Download the same.

    Step 3 : Once Download, open it and find out name of lookup attribute (“new_xxxxxx”) and check its casing.

    Step 4 : Verify it with the value which you are setting in the code it should be same.

    Actually for custom lookup Odata Keep first letter of lookup attribute  capital so in my case i use new_Expcontact  instead of new_expcontact.

    but one thing not considering new Web API contains all attributes in small case but why only lookup attribute first letter Capital.

    it confusing very much.


    Muhammad Sohail

    • Marked as answer by sohail450 Monday, August 22, 2016 11:10 AM
    Monday, August 22, 2016 11:08 AM