Forum Discussion
María José Pedreira
Jun 29, 2017Brass Contributor
Datetime Format for site columns - PNP
Hi, I need to add a new site column, with DateTime Type, using PnP. I can do that using next command: Add-PnPField -DisplayName "Birthday" -InternalName "dateBirthday" -Group "TEST" -Type Dat...
- Jun 29, 2017
Try this:
Add-PnPFieldFromXml '<Field Type="DateTime" DisplayName="My Test Column" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" Format="DateOnly" Group="Custom Columns" FriendlyDisplayFormat="Disabled" ID="{10ce4fed-921a-4d51-a870-534605bf89be}" SourceID="{6cf53ae4-314b-435e-9685-19b7f7b8df07}" StaticName="MyTestColumn2" Name="MyTestColumn2"></Field>'
María José Pedreira
Brass Contributor
Hi Pieter Veenstra,
your command works fine!
Could you give me explanation about ID and SourceID??... Is there any way to avoid guids?
Add-PnPFieldFromXml '<Field Type="DateTime" DisplayName="My Test Column" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" Format="DateOnly" Group="Custom Columns" FriendlyDisplayFormat="Disabled" ID="{10ce4fed-921a-4d51-a870-534605bf89be}" SourceID="{6cf53ae4-314b-435e-9685-19b7f7b8df07}" StaticName="MyTestColumn2" Name="MyTestColumn2"> </Field>'
Jun 29, 2017
The sourceID doesn't matter too much. you can even remove that. It's there as I exported the xml from an example field that I created.
The ID just needs to be unique in your site collection.
- María José PedreiraJun 29, 2017Brass Contributor
Ok, I´ll remove SourceId property and I´ll set a random ID with EnforceUniqueValues="TRUE"
Your response is perfect for me, thank you again!