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