Bug: 'spo file add' submitting $null or blank values as 'true'
See original GitHub issueDescription:
When adding a file and attempting to set a field using a variable, if the variable is $null or empty the value passed through is the string ‘true’.
Steps to reproduce:
$path = 'C:\MS365.jpg'
Scenario A)
Variable set to $null
$nullTitle = $null
o365 spo file add --webUrl https://contoso.sharepoint.com/sites/project-x --folder 'Shared Documents' --path $path --FileLeafRef 'Null Title.jpg' --Title $nullTitle
Expected
New file added to destination with Title attribute of '' (empty string)
Actual
New file added to destination with Title attribute of 'true'
Scenario B)
Variable set to ‘’ (empty string)
$emptyTitle = ''
o365 spo file add --webUrl https://contoso.sharepoint.com/sites/project-x --folder 'Shared Documents' --path $path --FileLeafRef 'Empty String Title.jpg' --Title $emptyTitle
Expected
New file added to destination with Title attribute of '' (empty string)
Actual
New file added to destination with Title attribute of 'true'
Scenario C) [Working as Expected]
Variable set to ‘not null or empty’
$stringTitle = 'not null or empty'
o365 spo file add --webUrl https://contoso.sharepoint.com/sites/project-x --folder 'Shared Documents' --path $path --FileLeafRef 'String Title.jpg' --Title $stringTitle
Expected/Actual
New file added to destination with Title attribute of 'not null or empty'
Additional notes:
This bug is particularly nasty when trying to pass an empty or null variable into a Date/Time, Number, or Lookup field as it will result in an incorrect type error.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Solved: Update file property to empty - null not working
Solved: At the end of my flow, I am trying to set one file property to empty/blank. The file is maintained in a...
Read more >Set default values for blank fields in Zaps - Zapier
Set default values for blank fields in Zaps · 1. Add Formatter to your Zap · 2. Set up the Default Value text...
Read more >SharePoint Online: How to Change Required Field Settings in ...
When users try to save an item or file without filling in the required field, they'll see an error message “You can't leave...
Read more >Bug listing with status UNCONFIRMED as at 2022/12/24 17 ...
Bug :128538 - "sys-apps/coreutils: /bin/hostname should be installed from coreutils ... an empty value when cross compiling" status:UNCONFIRMED resolution: ...
Read more >SharePoint Column Formatting - Highlight Null Values
That's all you have to do to get color coding for null/blank values. In the JSON, you reference a null/blank value by using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

That’s a bummer. Thanks for looking into it all the same!
On a related note:
The workaround I described above seemed way too inefficient, as it was iterating n number of times for each n number of objects to build a unique string, so I went back to the drawing board to come up with something cleaner.
Since iex worked just fine, I simply turned my existing ‘hardcoded’ command from earlier and set that as a string. Using a regular expression, I was able to match and remove options that had $null or empty values. I’ll post it here in case anyone could use it in the future:
Some items to consider and known limitations of this implementation:
--Help,--Verbose, and--Debug; if you require these options you’ll want to append it to your execution string (eg:iex ($executeO365SPOFileAdd + ' --Debug'))"'$null'"), it will not be matched.Feel free to let me know if you have any questions or recommendations on how to make this even cleaner!
Thank you again for taking a look at this Waldek, I really appreciate your efforts! ⭐️
You’re very welcome. Your assumption is correct, this issue has been spotted in PowerShell using non-immersive mode. Apologies for not including it in the original issue report.
Looking forward to your fix, in the meantime I’m working out how to dynamically build the parameters passed to ‘spo file add’ to only include non-null attributes.
Best regards,
Ramiro