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
Thank you so much, it is working
var payload = {
firstname: "test111.",
lastname : "lasttt",
bbo_salutation : 100000000,
"parentcustomerid_account@odata.bind" : "/accounts("+id+")"
};
Thanks again
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+")"
}
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)
parentcustomerid_account instead of ParentCustomerId
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156