sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Calculated Field Formula localization | AddFieldAsXml

Open Tanddant opened this issue 9 months ago • 8 comments

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

SharePoint CSOM

Developer environment

None

What browser(s) / client(s) have you tested

  • [ ] 💥 Internet Explorer
  • [x] 💥 Microsoft Edge
  • [ ] 💥 Google Chrome
  • [ ] 💥 FireFox
  • [ ] 💥 Safari
  • [ ] mobile (iOS/iPadOS)
  • [ ] mobile (Android)
  • [ ] not applicable
  • [ ] other (enter in the "Additional environment details" area below)

Additional environment details

Latest version of CSOM, PnP PowerShell or just REST API

Describe the bug / error

Something has changed in the behavior when adding SharePoint Fields (in this case using a provisioning engine) - I have a site with LCID 1030 (Danish) - and normally I would add the following field to the site

SchemaXML

<Field Type="Calculated" DisplayName="Week" EnforceUniqueValues="FALSE" Indexed="FALSE" Format="DateOnly" LCID="1030" ResultType="Text" Group="REDACTED" ID="{cb738292-b734-4866-8d94-edf6886348f6}" SourceID="{389dbd9b-06d5-4681-aa62-a996395fffdc}" StaticName="REDACTED_Week" Name="REDACTED_Week" CustomFormatter="" Required="FALSE" AllowDeletion="TRUE" Version="8" ReadOnly="TRUE"><Formula>=INT(([Report Date]-DATE(YEAR([Report Date]-WEEKDAY([Report Date]-1)+4),1,3)+WEEKDAY(DATE(YEAR([Report Date]-WEEKDAY([Report Date]-1)+4),1,3))+5)/7)</Formula></Field>

However when I now add that SiteField to a list I get an exception, investigating a bit further, it turns out that the ListFields formulas are now translated to the locale of the site, while the site fields aren't

Resulting in the following List field SchemaXML

<Field Type="Calculated" DisplayName="Week" EnforceUniqueValues="FALSE" Indexed="FALSE" Format="DateOnly" LCID="1030" ResultType="Text" Group="REDACTED" ID="{cb738292-b734-4866-8d94-edf6886348f6}" SourceID="{389dbd9b-06d5-4681-aa62-a996395fffdc}" StaticName="REDACTED_Week" Name="REDACTED_Week" CustomFormatter="" Required="FALSE" AllowDeletion="TRUE" Version="6" ReadOnly="TRUE" ColName="sql_variant1" RowOrdinal="0"><Formula>=INT((REDACTED_ReportDate-DATE(YEAR(REDACTED_ReportDate-WEEKDAY(REDACTED_ReportDate-1)+4),1,3)+WEEKDAY(DATE(YEAR(REDACTED_ReportDate-WEEKDAY(REDACTED_ReportDate-1)+4),1,3))+5)/7)</Formula><FieldRefs><FieldRef Name="REDACTED_ReportDate" /></FieldRefs></Field>

The key difference I notice is the formula is now translated

SiteField

=INT(([Report Date]-DATE(YEAR([Report Date]-WEEKDAY([Report Date]-1)+4),1,3)+WEEKDAY(DATE(YEAR([Report Date]-WEEKDAY([Report Date]-1)+4),1,3))+5)/7)

ListField

=HELTAL(([Report Date]-DATO(ÅR([Report Date]-UGEDAG([Report Date]-1)+4);1;3)+UGEDAG(DATO(ÅR([Report Date]-UGEDAG([Report Date]-1)+4);1;3))+5)/7)

This unpredictable experience makes it really hard to work with, I know from chatting with @KasperBoLarsen he's been struggling with the same thing when pulling content-types from the content-type hub

Steps to reproduce

  1. Create a site column and content-type in the content-type hub
  2. Use them on a site in a different language than the hub
  3. Cry

Expected behavior

I would expect consistent formulas within the site, I believe in the past the API would always just accept english, this seems like a change (perhaps related to knowledge agent) on the lists/library columns

Tanddant avatar Feb 27 '26 09:02 Tanddant

Hello @Tanddant, Thank you for bringing this issue to our attention. We will look into it and get back to you shortly.

Ashlesha-MSFT avatar Mar 02 '26 05:03 Ashlesha-MSFT

I was able to reproduce this behavior on a Danish (LCID 1030) site.

I will engage the engineering team to confirm whether this is expected localization behavior (UI/server-side) or if it should be considered a regression.

Ashlesha-MSFT avatar Mar 02 '26 13:03 Ashlesha-MSFT

We are experiencing the same issue in our Dutch tenant: calculated column formulas suddenly have to be entered in Dutch instead of English. As a result, our product that provisions sites no longer works.

When can we expect a concrete response on this? Otherwise, we will have to adjust our code for something that may not be permanent.

danielpastoor avatar Mar 03 '26 16:03 danielpastoor

My current workaround is to change this formular to something like generic like =IF((1 =2), "NFG","NA") , just in order to ensure that the provisioning doesn't fail, and then run a script that updates the formula in the correct language. At least it works

kasperbolarsen avatar Mar 03 '26 20:03 kasperbolarsen

Hi,

Does anyone has any updates on this issue?

danielpastoor avatar Mar 09 '26 11:03 danielpastoor

Hi, we are also experiencing the same issue across multiple tenants. It looks like the regional languagecode withun the site settings has suddenly changed. This is why the formula needs to be different, while in English and for example Dutch the formula seperator is different , vs ; Setting back the region languagecode to the oriinal value will solve the issue. Not sure why the region languagecode within the settings suddenly has changed within multiple sites on multiple tenants....

SanderSiep avatar Mar 11 '26 14:03 SanderSiep

I'm now also facing this issue when pulling a Content Type from the Content Type where there's a column using a default value that's a formula.

Tanddant avatar May 23 '26 13:05 Tanddant

@danielpastoor , @kasperbolarsen and @SanderSiep - let's see if you can help us on this a bit to provide a bit more details on the situation in your tenant.

What's the tenant default language where this issue has existed? - What's the language in the content type hub? - What about the site where issue exists?

We are trying to find the exact details for the repro - without good progress. Thanks for your input advance.

VesaJuvonen avatar Jun 02 '26 17:06 VesaJuvonen