sp-dev-fx-controls-react icon indicating copy to clipboard operation
sp-dev-fx-controls-react copied to clipboard

Error on rendering DynamicForm when having a Date Field with internal name starting with underscore ("_")

Open Lewin8687 opened this issue 1 year ago • 3 comments

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

Steps to Reproduce

  1. Create an extension using DynamicForm
  2. Add OOTB "End Date" or any date field named starting with a number (for example, "1Date") to a content type
  3. Add the content type to a document library
  4. Create a document out of the content type
  5. Attach the custom form to the list content type
  6. Add a date value to the new document from Details Pane
  7. Open custom form
  8. 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. image

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.

Lewin8687 avatar Jan 18 '24 20:01 Lewin8687

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost avatar Jan 18 '24 20:01 ghost

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

NishkalankBezawada avatar Jan 30 '24 17:01 NishkalankBezawada

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

Issue1738

@joelfmrodrigues @michaelmaillot Kindly review the stated PR.

Thanks, Nishkalank

NishkalankBezawada avatar Jan 30 '24 19:01 NishkalankBezawada