Forum Discussion
Add-PnPFieldFromXml - Assistance
- Jan 09, 2021
cawool Glad my approach worked for your original question.
For Current Error:
You are getting this error because whenever you create any field it converts the number and special characters in Name attribute to hexadecimal values to store it as internal name of your field. Maybe it is not liking the '4' character at the beginning of field name.
So, you can pass the different DisplayName (which you see in list view and list forms) and Name (internal name) in your XML like:
$docCreationDate = '<Field Type="DateTime" Format="DateOnly" DisplayName="Document Creation Date" Required="TRUE" Group="some group name" ID="{an iD}" Name="DocCreationDate" Description=""/>' Add-PnPFieldFromXml -FieldXml $docCreationDate $fourDate = '<Field Type="DateTime" Format="DateOnly" DisplayName="4 Date" Required="TRUE" Group="some group name" ID="{an iD}" Name="FourDate" Description=""/>' Add-PnPFieldFromXml -FieldXml $fourDate
Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Hi,
I managed to get this working. It was the GUID that wasn't generating a unique ID each time. Fixed it with:
$FieldID = New-Guid
However, for some reason adding a custom DateTime field always results in the below error no matter what the GUID is/starts with.
Add-PnPFieldFromXml : Name cannot begin with the '4' character, hexadecimal value 0x34.
I can manually create it no problem and was hoping to use Get-PnPField with -Includes "SchemaXML" to see resultant XML but it doesn't like that... at all.
cawool Glad my approach worked for your original question.
For Current Error:
You are getting this error because whenever you create any field it converts the number and special characters in Name attribute to hexadecimal values to store it as internal name of your field. Maybe it is not liking the '4' character at the beginning of field name.
So, you can pass the different DisplayName (which you see in list view and list forms) and Name (internal name) in your XML like:
$docCreationDate = '<Field Type="DateTime" Format="DateOnly" DisplayName="Document Creation Date" Required="TRUE" Group="some group name" ID="{an iD}" Name="DocCreationDate" Description=""/>'
Add-PnPFieldFromXml -FieldXml $docCreationDate
$fourDate = '<Field Type="DateTime" Format="DateOnly" DisplayName="4 Date" Required="TRUE" Group="some group name" ID="{an iD}" Name="FourDate" Description=""/>'
Add-PnPFieldFromXml -FieldXml $fourDate
Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- cawoolJan 09, 2021Copper Contributor
ganeshsanap Hi,
We have success! Not sure what was going on before but my DisplayName did not have a number in it even though it was complaining about it. I deleted the site and started a fresh and made sure my code was clean and as it should be.
Thank you for your assistance, much appreciated!