PnP-Sites-Core icon indicating copy to clipboard operation
PnP-Sites-Core copied to clipboard

[BUG] Missing parser.ParseString in UpdateListItem for Lookup fields

Open SLTKA opened this issue 3 years ago • 3 comments

Category

[x] Bug [ ] Enhancement Environment

[x] Office 365 / SharePoint Online [ ] SharePoint 2016 [ ] SharePoint 2013 Expected or Desired Behavior

Using any token in provisioning template should use the correct token/stringValue for Lookup value Observed Behavior

When creating DataRows in a list, the code fails with error Apply-PnPProvisioningTemplate : Input string was not in a correct format.

Explanation: There is token parsing code on the line 295, but if parsed value converts to, for example, 2, the code on the line 433 returns false as 2 has no splitting characters. After that, code on the line 444 executes, but instead of using processed value (with replaced tokens) it is using raw tokenized value (valuesToSet[key]) and int.Parse fails.

Possible solution: Use value instead of valuesToSet[key] on the line 444 in ListItemUtilities.cs Potentially the line 435 needs a fix as well because value is used in the condition, but never used to build the lookup value (multiValue) Just a suggestion to replace everything from 433 to 446 with something like

multiValue = value
    .Split(new [] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
    .Select(v => int.Parse(v)).ToArray();

and possibly check some logic to on the following code so if multiValue is empty this will unset existing value from the list record in Overwrite mode

Steps to Reproduce

Provision a list with data where a field is using a parameter value: ..... pnp:Parameters <pnp:Parameter Key="MyNumber" Required="true"/> ..... <pnp:DataRows KeyColumn="Title" UpdateBehavior="Skip"> pnp:DataRow <pnp:DataValue FieldName="ALookupColumn">{parameter:MyNumber}</pnp:DataValue> </pnp:DataRow> </pnp:DataRows> </pnp:ListInstance>

Link to code https://github.com/pnp/PnP-Sites-Core/blob/cee6297d89f7eb9a939a4f0218a0f6ff3b72393f/Core/OfficeDevPnP.Core/Framework/Provisioning/ObjectHandlers/Utilities/ListItemUtilities.cs#L444

SLTKA avatar Sep 24 '20 06:09 SLTKA

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

ghost avatar Sep 24 '20 06:09 ghost

hey @SLTKA , as you seem to be on the good track to fix the issue, could you please test it and create a pull request ?

jackpoz avatar Sep 25 '20 15:09 jackpoz

@jackpoz I will try in the next couple days

SLTKA avatar Sep 28 '20 03:09 SLTKA