A validation error occurred in dynamics-crm - dynamics-crm

In my code, I insert from one date field to another date field, then update my entity with the new data and debugging my code. I get this exception:
A validation error occurred. The value of on record of type is outside the valid range.
When I change the same field in CRM UI I get no error. Where should I look for? What is the problem?

Normally this error will look like:
A validation error occurred. The value of 'field_name' on record of type 'entity_name' is outside the valid range.
You have to make sure, if the field is optionset - then the value (ex.10000000) passed in code is within the available range of options in optionset customization (ex: 10000000, 10000001, 10000002)
You said date field, verify if the date fields between the entities are of same type (like date only, date time, timezone specific, etc). Also the retrieval from CRM using SDK will give you UTC whereas the date value assignments in code while create/update will be parsed to UTC.. check that too for possible date range like 31st November 2017.

Related

Dynamics 365, Entity View, format date field to "Month Year"

I am working on an entity view that displays billing records with associated date. This date field needs to be displayed as "Month - Year". Unfortunately, I am not able to find a way to format this date field outside of modifying the entity and even then, I only have the option for date only or date and time.
I have noticed that I can select the field and click on Change Properties. There I have "Web Resource" and Function Name. I have tried creating a web resource with a function that returns some data. Set everything up, saved and published. This function is not even found in dev tools. Only examples that I have for it are dealing with using this method for icons:https://www.c-sharpcorner.com/article/view-customization-with-javascript-in-dynamics-365/
In another example the suggestion is to use calculated fields, but this would cause me to lose date sorting and filtering on the form.
That view-based JavaScript seems to be to choose an icon. I'm not sure it would allow you to reformat actual data in the view. And if you're looking for assistance with trying to do that, you'd probably get more help if you posted the code.
Besides the JavaScript approach, you might want to think about creating a separate text field to hold the "Month - Year" value. Then you could use a workflow, plugin, or JavaScript to populate it when the datetime field changes.
One of the free workflow tool packages (Jason Lattimer's, Aiden Kaskela's, or Andrew Butenko's) probably has the ability to parse the date so you can format the month and year, and store the string in the separate field. This would be a no-code option.
Alternatively, you could write a plugin to reformat the datetime values and register it on the RetrieveMultiple message of the entity.
I'd probably go with a separate field and an off-the-shelf workflow utility to populate it.
There are several ways:
1. Setting->Administration->System Setting->Format->Customize,
2. http://prntscr.com/ph42nc,
3. or use on load with js to change date format more on this subject here: How to change date format in JavaScript

400 - Bad Request while saving Date Only field in CRM using Web API

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.
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.
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.
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.

Create A new DATE field from Existing Short Text Field in MS ACCESS using Append Query

I have an MS ACCESS employee database.
It contains 1550 records and there are around 7 date fields, however the field types are Short Text.
The value of all these 7 date fields for the 1550 records are entered as yyyymmdd (e.g. 19870220). They are not of Date/Time field yet.
I would like to either change all these 7 fields for the 1550 records to date fields and the format them as "MM/DD/YYYY".
I've created Update query and also added new fields that are Date/time fields, and used CDATE function like this UptateTO: CDATE([Birthdate]), but I got error.
I used the Append query, also I got error.
Somehow, CDATE() function is not converting the value of the text field to date.
I'm using ACCESS 2013.
Use this expression to update your new date field:
Set TrueBirthDate = CDate(Format([BirthDate], "####/##/##"))
The values carries no format. For display, you can set this in the Format property of the field, or the default format from your Windows settings will be used.

CRM 2013 Entity.GetAttributeValue<T> datetime to string

When adding an date record to crm 2013, its removing 2 hours from my record.
Which is an expected behavoir of the crm as a timezones correction.
The next expected behavior, retreiving the entity using the organisationService RetrieveMultiple api call, returns me the same record without the extra 2 hours.
Now the strange magic begins, when using the Entity.GetAttributeValue(fieldname) it should give me the datetime with the extra 2 hours as it is a setting from the crm. But this is what i get:
Create record: '01/10/2014'
CRM stores: '30/09/2014 22:00:00'
Retreive entity results to: '30/09/2014 22:00:00'
Use Entity.GetAttributeValue<DateTime>(fieldname) results to: '30/09/2014 00:00:00'
Why does it not say 01/10/2014 after using that method ?
GetAttributeValue is just an helper, if the DateTime field value inside CRM is null, GetAttributeValue returns DateTime.MinValue.
You need always to use .ToLocalTime() to get the local DateTime value instead of the UTC value.

Error in retaining an invalid value for date fields in form

I am relatively new to the Spring framework and am facing a problem that I am not sure where I am going wrong.
I have a form with two date fields, date 1 and date 2. If date 1 field is an invalid date and the date 2 is a valid date, when validations are performed, the date 1 field's invalid value is not displayed. Instead the date 2 value is populated in the date 1 field box.
Could someone please tell me why and where I am going wrong.
I believe this is a framework error with the way I have configured spring and not a problem with my code. I tried debugging through my code and it works as it is supposed to.
I had the same issue. It looks like you are using a customDateEditor that is different from the one that Spring provides. Check if you are importing
org.springframework.beans.propertyeditors.CustomDateEditor
in your customPropertyEditorRegistrar class... It will probably help.

Resources