1
votes

Lets asume we have a Account entity in Dynamics 365, account have c5 number and name attributes.

Now i want to create a new account through the dynamics 365 Web API. I create an account object with c5 number, name and i add an aditional attribute lastname. When i post this account object to Web API, i will get an error like :

    "code":"","message":"The property 'lastname' does not exist on type 'Microsoft.Dynamics.CRM.account'. Make sure to only use property names that are defined by the type.","innererror":{

  "message":"The property 'lastname' does not exist on type 'Microsoft.Dynamics.CRM.account'. Make sure to only use property names that are defined by the ...

I really dont uderstand why Dynamics 365 Web API just cant ignore property's which it cant use?

At this specific scenarion it means that if we delete name property on the account entity, there are possibility that all our systems which talks to the Web API will crash.

How can i get around this problem? Are there anyway to force dynamics 365 Web API to ignore some propertys?

1
You'll have to accept that in the end, the application will have to try to insert into the requested database column - it is expected behavior that this will fail for a non-existent column. As for deleting: this would only be the case for custom attributes - you cannot delete standard/managed attributes.Filburt
I wonder if you could use the MetaData service to find out the attributes of a given entity at run-time, and then filter your POST to only include the attributes that are provided in the instance you are connected to. Seems like a likely candidate given the description on MSDN - msdn.microsoft.com/en-us/library/mt607522.aspx#Retrieving attributes Some SO answers show how to go about this too.Mr Moose
If retrieving the entity metadata is too much overhead, you could create a "default record" with all (needed) attributes and retrieve this record with new ColumnSet(true) (SELECT * FROM) which will yield an entity instance that has all valid attributes. Reset its ID to null, update attributes as needed and .Create() it. Use at own risk. I'd still recommend to decide touching attributes based on the entity (logical name) and/or entity metadata.Filburt
I doubt that many systems automatically ignore operations targeted at objects that don't exist. If they did so silently, it could open a door to many other issues. Anyway, maybe wrap your code in a try / catch block and on the exceptions, loop until you remove all properties that don't exist in the target system.Aron

1 Answers

0
votes

Web Api not only do not ignore not used values, but even on update, it updates all values You send, even they are equal. As one step can be - ignore this value by setting it to non NonSerialized, it will be excluded. Also, You can define naming to class members, so You do not have to worry about how they are named in code.

`[Serializable]
public class Account    {
    [NonSerialized]
    public string lastname;

    [JsonProperty("firstname")]
    public string firstName;

    [JsonProperty("index")]
    public int c5;
}