ListItemAllFields string converted to a date #1571
-
Hi, I have a custom field named “Number”, the type of the field is string, with the following text: "0004603-4-1" When I retrieve the field in the collection ListItemAllFields, I see the library is converting the value to a Date. How can I retrieve the raw values using the same collection? Please see attachemnt with the example/image Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
Hi, Can someone please help me with this issue? This is causing issues in production Thanks |
Beta Was this translation helpful? Give feedback.
-
@sabrinadeveloper2023 : if the string can be parsed as DateTime it's returned as such (see https://github.com/pnp/pnpcore/blob/dev/src/sdk/PnP.Core/Services/Core/JsonMappingHelper.cs#L1049-L1058). The code path that does this has no knowledge about the FieldType at the moment of parsing, hence this best effort approach. Structural approach would be to ensure it has access to the field types, for now can you see if loading and using the Below snippet was copied from one of our test cases: var myList2 = context2.Web.Lists.FirstOrDefault(p => p.Title == listTitle);
await myList2.LoadAsync(p => p.Items.QueryProperties(p => p.Title, p => p.FieldValuesAsText));
foreach (var item2 in myList2.Items.AsRequested())
{
Assert.IsTrue(item2.Title == "okido");
Assert.IsTrue(item2.FieldValuesAsText.Values["MetaInfo"].ToString().Contains("{DFC8691F-2432-4741-B780-3CAE3235A612}:SW|MyStringWithXmlValues"));
} |
Beta Was this translation helpful? Give feedback.
-
@jansenbe Thanks for your answer. I have implemented your suggestions and the custom field I need to retrieve is not part of the collection item.FieldValuesAsText.Values. Please let me know what do you think as alternative solution to retrieve the value in the custom field as text. Thanks for your help, much appreciated |
Beta Was this translation helpful? Give feedback.
-
@Magnus-K-work Thanks for reproducing this problem! Much appreciated your input as this is causing a big issue in production and I am not sure what is the best approach ☹. @jansenbe I have tried several approaches but none of them works. Thanks. |
Beta Was this translation helpful? Give feedback.
As I'm learning PnP.Core from scratch, I tried to replicate this issue and I can see @sabrinadeveloper2023's issue as well.
Steps to replicate the issue:
M…