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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Create a new record and populate a lookup field using js

(0) ShareShare
ReportReport
Posted on by 2 User Group Leader

Hi, 
I get an error when trying to run the js code below. The idea is to create a new record and populate 3 fields on create. It seems to run fine when i remove the lookup field, but when adding that, then I get the following error: 

An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type.

This is the code i try to run: 

function createContractFlowRecord(contractType) {

//Get Account GUID
var accountid = Xrm.Page.data.entity.getId();

//Get field "name" from Account entity
var accountName = Xrm.Page.getAttribute("name").getValue();
console.log(accountName);
console.log(accountid);

var entityLogicalName = "linak_contractflow";
var data = {
"linak_Account@odata.bind": "/Account(0e924ec4-3a3c-ea11-a812-000d3a4aa4e2)",
"linak_Contracttype": contractType,
"linak_name": "Test vit"

};

// create contract flow record
Xrm.WebApi.createRecord("linak_contractflow", data).then(
function success(result) {
console.log("Contract flow record created with ID: " + result.id);
// perform operations on record creation
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
}

Can you see what I should be doing differently? I am testing it against D365 CE 9.1.0000.15051

BR, Vivian

I have the same question (0)
  • Verified answer
    Marco.P Profile Picture
    2,405 on at

    Hi,

    Try with

    linak_Account@odata.bind": "/accounts

  • Verified answer
    Miguel Lourenco Profile Picture
    on at

    Hi,

    I believe Marco is correct.

    However, next time use CrmRestBuilder ( https://github.com/jlattimer/CRMRESTBuilder), this will help you to automatically create the requests based on what you want.

  • Suggested answer
    Vivian Voss Profile Picture
    2 User Group Leader on at

    Hi Marco and Miguel,

    Thank you for your responses. Will definitely try that tool next time, thanks :)

    I finally managed to figure it out and it seems to be a combination of things:

    * it should be  accounts instead of account, yes

    * linak_Contracttype field should not be with at capital C

    Br, Vivian

  • r_m_w Profile Picture
    15 on at

    Does adding an s apply to all entities - specifically custom entities?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans