When the business is working with a solution, build in SharePoint Online, they often have new requirements. One of these requiremtens most time is, to add new fields to a list or content type. Because we have the SharePoint PnP extensions, the task for adding a new field could easily be solved with the Add-PnPField cmdlet. But…

… often the user wants to have a new field in a special position within the list or content type. This could also be solved using PowerShell, but we need some CSOM code for the solution. The field order is part of the FieldLinks collection of the content type. Most of the time, we have already a field in the content type that could be used as the anchor, after which we want to place the new file. So, first, we need the position of our already existing field (the new field should already be created). We get this information with the following script:

With the position of the anchor field, we can use the following script to move our new field to the desired position in the content type. That could be done with the following script:

When we put this together, we can use the following script to do the move during a provisioning process:

If necessary, and this often makes sense, we can put all these scripts together and use the functions directly in one script.

Advertisements