PnP-Sites-Core
PnP-Sites-Core copied to clipboard
[BUG] Missing parser.ParseString in UpdateListItem for Lookup fields
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
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
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 I will try in the next couple days