sp-dev-fx-controls-react
sp-dev-fx-controls-react copied to clipboard
Error on rendering DynamicForm when having a Date Field with internal name starting with underscore ("_")
Category
[ ] Enhancement
[X] Bug
[ ] Question
Version: [3.15.0]
Expected / Desired Behavior
The form should be rendered successfully.
Observed Behavior
The form dispears and errors show in the console.
Steps to Reproduce
- Create an extension using DynamicForm
- Add OOTB "End Date" or any date field named starting with a number (for example, "1Date") to a content type
- Add the content type to a document library
- Create a document out of the content type
- Attach the custom form to the list content type
- Add a date value to the new document from Details Pane
- Open custom form
- Issue: errors show up in console, the form shows and disappears.
Investigation
The reason could be the line to get the date value from the list item.
The key of the date field value in list item is not the same as field internal name. For example, for OOTB date field "End Date", internal name is "EndDate", but in list item, its saved as "OData__EndDate". Same to other fields which internal name starts with underscore "". SharePoint will prefix it with "OData_" to make DynamicForm unable to get the value.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Hello @Lewin8687,
I have found the issue, and will soon creating a PR on this.
@joelfmrodrigues @AJIXuMuK @michaelmaillot Please assign this to me.
Thanks, Nishkalank
Hello @Lewin8687,
I have created a PR on this.
Problem statement
When a date column is created with an underscore or '_' at the begining, the form is not rendered correctly. For instance, if a column with name '_AccomplishedDate', '1AccomplishedDate' is created, and the list form is not rendered, instead it errors out.
Solution
On investigating the issue, I have created columns as below
Column Name | Type | Internal Name (Retrieved from Item) |
---|---|---|
1EFDate | DateTime | OData__x0031_EFDate |
2EFDate | DateTime | OData__x0032_EFDate |
_EFDate3 | DateTime | OData__EFDate3 |
12312EDate | DateTime | OData__x0031_2312EDate |
%Test | Text | OData__x0025_Test |
1Test | DateTime | OData__x0031_Test |
Since the FieldInternal names are not matching with the Internal names of the columns, this issue is spotted. By checking the FieldInternal name as below, and validating, the issue is resolved.
if (fieldName.startsWith('_x') || fieldName.startsWith('_')) {
fieldName = `OData_${fieldName}`;
}
Screenshot
@joelfmrodrigues @michaelmaillot Kindly review the stated PR.
Thanks, Nishkalank