Microsoft 365 : SharePoint online – REST API – Getting list items – resolving error – Cannot complete this action. OR Please try again – Microsoft.SharePoint.SPException or Input string was not in a correct format – System.FormatException

Microsoft 365 - SharePoint Online - List REST API - error while getting items from list - issue because of field special character
Microsoft 365 - SharePoint Online - List REST API - error while getting items from list - issue because of field special character

Hi All,

Greetings for the day!!! Today new issue and solution 🙂

Background / Details

  • We have SharePoint list – DemoList
  • List have columns which are created from UI
  • So internal names are set with special characters as given name while creating columns from UI
  • For ex. one of the column created by our user having name with special character – ?test – internal name becomes – _x003f_test as
Microsoft 365 - SharePoint Online - List - Adding column with special character
fig : Microsoft 365 – SharePoint Online – List – Adding column with special character
  • We are using REST API to get all items from the respective list

NOTE : This error is not happening in all tenants. I have noticed that in some tenants (my local tenant) it worked

Issue

Microsoft 365 - SharePoint Online - List REST API - error while getting items from list - issue because of field special character
fig : Microsoft 365 – SharePoint Online – List REST API – error while getting items from list – issue because of field special character

This XML file does not appear to have any style information associated with it. The document tree is shown below.
-2147467259, Microsoft.SharePoint.SPException Cannot complete this action. Please try again.

  • This is because of site column created with special character – ?test – internal name – _x003f_test
  • When we select this field in REST call, we get an error as

Microsoft.SharePoint.SPException The field or property ‘_x003f_test’ does not exist.

Microsoft 365 - SharePoint Online - error in REST call when select with field with special character
fig : Microsoft 365 – SharePoint Online – error in REST call when select with field with special character

-1, System.FormatException Input string was not in a correct format.

Microsoft 365 - SharePoint Online - error while getting item with field as special character
fig : Microsoft 365 – SharePoint Online – error while getting item with field as special character

Solution / Workaround – There are couple of workaround

  • When we exclude this column from REST API using “select“, it started like – https://knowledgejunction1.sharepoint.com/_api/web/getlistbytitle(‘DemoList’)/items?$select=Title
  • Either create same field without special character and start using those
  • OR recreate list with proper naming conventions for site columns / list columns
  • Follow best practice for creating site columns – Never ever create site columns from UI

Best Practice to create Site Columns

  • Use PowerShell to create site columns
    • Create proper CSV file with details – column name like – “DisplayName”, “InternalName”, “Required” etc
Microsoft 365 - SharePoint online - sample CSV file for creating site columns
fig : Microsoft 365 – SharePoint online – sample CSV file for creating site columns

Thanks for reading !! HAVE A FANTASTIC LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.