Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Error while setting the Lookup Value

Posted on by 60

Hi

i want to create a new contact when a specific property is change of Account entity, 

i ran into problem while setting the lookup value in web API create request

my request code is 

var Sdk = window.Sdk || {};

/**
* Request to execute a create operation
*/
debugger;
Sdk.CreateRequest = function (entityName, payload) {
this.etn = entityName;
this.payload = payload;
};
Sdk.CreateRequest.prototype.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {},
operationType: 2, // This is a CRUD operation. Use '0' for actions and '1' for functions
operationName: "Create",
};
};
// Construct a request object from the metadata
var payload = {
firstname: "Contact first name",
lastname : "Contact Last name",
cc_salutation : 100000000,
["ParentCustomerId@odata.bind"] : "/accounts("+id+")"
};


console.log("payload =>"+JSON.stringify(payload));

var createRequest = new Sdk.CreateRequest("contact", payload);

// Use the request object to execute the function
window.parent.Xrm.WebApi.online.execute(createRequest).then(
function (result) {
if (result.ok) {
alert("Created Successfully");
console.log("Status: %s %s", result.status, result.statusText);
// perform other operations as required;
}
},
function (error) {
alert("Failed "+error.message);
console.log(error.message);
// handle error conditions
}
);

but i have this error message

An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'ParentCustomerId' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.
at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadUndeclaredProperty(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean propertyWithValue)
at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithoutValue(IODataJsonLightReaderResourceState resourceState, String propertyName)
at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass9_0.<ReadResourceContent>b__0(PropertyParsingResult propertyParsingResult, String propertyName)
at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)
at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)
at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()
at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)
at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)
at Microsoft.OData.ODataReaderCore.ReadImplementation()
at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)
at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)
at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)

my lookup field value in payload is not empty, i have consoled the paylaod and i can see the lookup value

payload =>{"firstname":"Contact first name","lastname":"Contact Last name","cc_salutation":100000000,"ParentCustomerId@odata.bind":"/accounts({XXXXXX-XXX-XXXX})"}

Any help will be appreciated.

Thanks

  • Bilal079 Profile Picture
    Bilal079 60 on at
    RE: Error while setting the Lookup Value

    Thank you so much, it is working

    var payload = {

       firstname: "test111.",

       lastname : "lasttt",

       bbo_salutation : 100000000,

       "parentcustomerid_account@odata.bind" : "/accounts("+id+")"

    };

    Thanks again

  • Verified answer
    ajyendra Profile Picture
    ajyendra 1,730 on at
    RE: Error while setting the Lookup Value

    var payload = {

      firstname: "test111.",

      lastname : "lasttt",

      bbo_salutation : 100000000,

      "parentcustomerid_account@odata.bind" : "/accounts("+id+")"

    }

    OR

    var payload = {

      firstname: "test111.",

      lastname : "lasttt",

      bbo_salutation : 100000000,

      parentcustomerid_account@odata.bind : "/accounts("+id+")"

    }

  • Bilal079 Profile Picture
    Bilal079 60 on at
    RE: Error while setting the Lookup Value

    Hi @Ajyendra

    Thanks for your response

    i have tried this

    var payload = {

       firstname: "test111.",

       lastname : "lasttt",

       bbo_salutation : 100000000,

       ["parentcustomerid_account"] : "/accounts("+id+")"

    };

    and got this error

    An error occurred while validating input parameters: Microsoft.OData.ODataException: A 'PrimitiveValue' node with non-null value was found when trying to read the value of the property 'parentcustomerid_account'; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected.

      at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ValidateExpandedNestedResourceInfoPropertyValue(IJsonReader jsonReader, Nullable`1 isCollection, String propertyName)

      at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithValue(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean isDeltaResourceSet)

      at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass9_0.<ReadResourceContent>b__0(PropertyParsingResult propertyParsingResult, String propertyName)

      at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)

      at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)

      at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()

      at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)

      at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)

      at Microsoft.OData.ODataReaderCore.ReadImplementation()

      at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)

      at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)

      at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)

      at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)

  • Suggested answer
    ajyendra Profile Picture
    ajyendra 1,730 on at
    RE: Error while setting the Lookup Value

    parentcustomerid_account instead of ParentCustomerId

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans