web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Issue while inserting ...
Power Pages
Suggested Answer

Issue while inserting Contact lookup value (server-side logic create record)

(0) ShareShare
ReportReport
Posted on by 2

I have created a custom table named dev_application, which includes a Contact lookup field (dev_applicationcreatedby).

When I try to create a record using server-side logic and include a value for this Contact lookup field, the request fails with an error from Dataverse. However, the record is created successfully when I exclude the lookup field. If I remove the lookup field from the payload, everything works as expected. I have verified that the current user ID exists in the Contact table. I have also assigned all required table permissions to the authenticated user web role.

Could someone please help me understand what might be wrong with the lookup configuration or payload format? Any guidance would be greatly appreciated.

function post() {
    try {
        Server.Logger.Log("POST called");
        const data = JSON.parse(Server.Context.Body);
        const entitySetName = Server.Context.QueryParameters["entitySetName"];
        var userid = Server.User.contactid;
        data["dev_applicationcreatedby@odata.bind"] =  `/contacts(${userid})`
        return Server.Connector.Dataverse.CreateRecord(entitySetName, JSON.stringify(data));      
    } catch (err) {
        Server.Logger.Error("POST failed: " + err.message);
        return JSON.stringify({ status: "error", method: "POST", message: err });
    }
}
I have the same question (0)
  • Assisted by AI
    Vish WR Profile Picture
    1,045 on at
     
     

    Your issue is most likely caused by how the Contact lookup is being referenced in the Dataverse payload.

    Key points:

    * Ensure the lookup format is correct: /contacts(GUID) with no braces.

    * Verify dev_applicationcreatedby is the correct lookup schema (navigation property), not just the display or column name.

    * Confirm table permissions for Contact include at least Read access for the portal user.

    * Ensure entitySetName is the correct Dataverse entity set name  

    Most common root cause: incorrect user/contact ID or wrong lookup binding format.

    Vishnu WR
     
    Please âœ… Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like â™¥

     
  • Suggested answer
    rezarizvii Profile Picture
    333 on at
    Hi @Vish WR, if you are going to post generic AI-generated answers, please ensure to tag your messages as "AI-assisted" properly to ensure clarity in the forum. OP could easily ask any LLM to get the same generic and vague response.
     
    Hi @CU16041033-0, hope you are doing well.
     
    If you have verified the table permissions, assigned them to the authenticated users web role, and ensured the GUID exists in the contact table, it seems the error is caused by the syntax of your OData bind. According to Microsoft, the name of the field that should appear before the '@odata.bind' is supposed to be the Navigation Property Name, NOT the field's logical name [Reference from MS Learn]. It seems you are using the logical name of the lookup field to make the OData bind.
     
    Here's how to confirm the navigation property name of the lookup field:
    • Go to this URL: https://[your-org-URL]/api/data/v9.2/$metadata
      You can also find this URL by going to Settings and then Developer resources. Just make sure to append /$metadata at the end of the Web API endpoint.
    • Use "Ctrl + F" on Windows (or the equivalent shortcut to search in the page on Mac) and look for the lookup column you wish to bind. In your case: dev_applicationcreatedby
    • Use the Navigation Property Name you find there as is in your code. Remember, it is case sensitive, so you should copy it as you see on the /$metadata page.
      It should be in this format: data["<Case-Sensitive-Navigation-Property-Name>@odata.bind"] =  `/contacts(${userid})`
     
     
    Please âœ… Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item.
    If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like! 🩷
    _______________________________
    Reza M. Rizvi
    Reza M. Rizvi
    LinkedIn  |  Email
  • Suggested answer
    11manish Profile Picture
    1,381 on at
    The issue is most likely caused by either incorrect navigation property name or missing table permissions on the Contact table. Even though the record exists, Dataverse (especially via Power Pages) requires proper read access and correct relationship binding for lookup fields to work.
     
    try below code :
    function post() {
        try {
            Server.Logger.Log("POST called");
            const data = JSON.parse(Server.Context.Body);
            const entitySetName = Server.Context.QueryParameters["entitySetName"];
    
            var userid = Server.User.contactid?.replace(/[{}]/g, "");
    
            if (userid) {
                data["dev_applicationcreatedby@odata.bind"] = `/contacts(${userid})`;
            }
    
            return Server.Connector.Dataverse.CreateRecord(entitySetName, JSON.stringify(data));
    
        } catch (err) {
            Server.Logger.Error("POST failed: " + err.message);
            return JSON.stringify({ status: "error", method: "POST", message: err });
        }
    }
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
rezarizvii Profile Picture

rezarizvii 61

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 40 Most Valuable Professional

#3
DP_Prabh Profile Picture

DP_Prabh 26

Last 30 days Overall leaderboard