Thursday, April 12, 2018

Expose values from an existing InfoPath field to a SharePoint field


Photo by adrian on Unsplash

Ok, I know InfoPath is not the future and all, but I happen to have one client which has an old InfoPath solution for reporting incidents at their facility. I have previously migrated this from SharePoint 2007 to 2013, which involved some XML manipulation in the process, and I did spare you a blog post on this :-)

Either way, the lists of incidents which goes back years have now been hooked up to PowerBI via the on-premises gateway, so the customer is slowly taking the leap to the cloud.

And, turns out, the date field which has the date of the incident was never exposed as a SharePoint field, a field which is pretty nice to report on for incidents.

I fired up SharePoint designer, promoted the field in question and re-published the InfoPath form. This ensured all new items would have a date in the incident date field, but all existing items were still blank. So how could I in the easiest way possible get the value from the XML files promoted to the SharePoint field? Turns out it was very very very easy.

It was a matter of looping over all list items and running SystemUpdate() on them. This ensured modified date and modified by fields were not changed, but the value got populated.

Below is my PnP PowerShell snippet which saved the day.

Get-PnPListItem -List "Incidents" |% { $_.SystemUpdate();$_.Context.ExecuteQuery() }