2

I am using Microsoft Dynamics 365 Web API approach to interacting with CRM data.

Here I want to update the field with type: DATE and TIME.

Screenshot of field setting

Date value I am passing in the request body is as below:

"packfirstday":"1-15-2018"

Except for above, I have also tried with DateTime and with different date formats. e.g.

mm-dd-yyyy
m-dd-yyyy
mm/dd/yyyy
yyyy/mm/dd
yyyy-mm-dd

PS: I try to post without date field it is saving details successfully.

I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216

1 Answers1

3

The problem is not with the code, the simple misunderstanding.

There are 2 components namely Behavior & Format. You have Format set as 'Date only' not the Behavior. Behavior decides the Database terms whereas Format is used for displaying datepicker controls in Form.

enter image description here

So when you set the field in web api with only date part - the CRM database expects time part also.

Either set behavior also as date only, so this will work:

"packfirstday":"2018-01-15" //YYYY-mm-dd format

Or change your code to pass time part also:

"packfirstday":"2018-01-15T11:10:00.000Z" //UTC offset

Since user local behavior still expects the time part.

iBug
  • 35,554
  • 7
  • 89
  • 134
  • 1
    I tried 1st approach **setting behaviour as Date Only** creating another field and it is **working as expected**. **_But as I do have a client's CRM and once I change the behaviour to `Date-Only` it won't allow again to change that field._** So I tried with 2nd approach i.e. using **UTC offset** on the existing field but it is not working and throwing error **400-BadRequest**. Can you guide me through this second approach? – I Love Stackoverflow Jan 15 '18 at 06:26
  • 1
    As edited, it was expecting '.' instead of ':' for the milliseconds. Marked as the answer for your help @Arun sir. Thank you again. – I Love Stackoverflow Jan 15 '18 at 07:37