The query string \”comment\” is missing or invalid.
Table of contents:
I was seeing this kind of error in Nintex for Office 365 workflows for some time, but actually never had enough determination to check what is the root cause. However when customer started asking, I started digging.
Symptoms
The error The query string \"comment\" is missing or invalid
appears usually, once the workflow task is completed and workflow is trying to check-in item providing comment from task, as the check-in comment. Sometimes workflow gets suspended, showing a long error message, that looks like below:
RequestorId: 2dcb7a0f-917b-f86f-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ApplicationException: HTTP 400 {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The query string \"comment\" is missing or invalid."}}} ........ at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) Exception from activity Throw If Sequence Sequence TryCatch Sequence Microsoft.SharePoint.WorkflowServices.Activities.RetryForDurationPolicy HttpPost Check In Item NintexActivities.WorkflowXaml_590a5ff5_9b4a_4c6e_a528_f22c544e7779 Sequence Microsoft.SharePoint.WorkflowServices.Activities.AppOnlySequence Rejected ControlFlowStep Assign a task Approval request Sequence If If While Routing "State Machine" Sequence Flowchart 01 Request approval - DEE.WorkflowXaml_03d7ffe8_c113_4610_8142_350ab919bb39". Instance last run on: 2021-07-14T04:16:23.217.
What can I read from it? That there was an error in the “comment” field and then carefully reading through stack trace I can figure out, it is related to “Check In Item” action. Bummer. The workflow cannot be resumed no matter what you do. You need to fix the issue and restart it.
Reason
The reason turned out to be pretty simple. The comment contained special character – single quote (‘). But, as per my further investigation, the same situation occurs if comment contains ampersand (&). And if the check-in is done using the simple “Check In Item” action. Why?
Because Nintex service is using POST to check in document using SharePoint endpoints without fully escaping special characters. This is what Nintex Support found in their logs:
https://poszytek.sharepoint.com/sites/mysite/_api/web/getfilebyserverrelativeurl(@Url)/CheckIn(comment=@Comment,%20checkintype=@CheckinType)?%40Url='%2Fsites%2Fmysite%2FDocuments%2FTest%20document.docx'&%40Comment=<https://poszytek.sharepoint.com/sites/mysite/_api/web/getfilebyserverrelativeurl(@Url)/CheckIn(comment=@Comment,%20checkintype=@CheckinType)?%40Url='%2Fsites%2Fmysite%2FDocuments%2FTest%20document.docx'&%40Comment=>'
%E2%80%A2+%3Cb%3EApprover+rejection+comment:+%3C%2Fb%3E%3Cbr%2F%3ERejected+by:+Poszytek%2C+Tomasz+S+%7C+%3Cbr%2F%3ERejection+date%2Ftime:+13.07.2021+11:47+-+13.07.2021+12:02+%7C+%3Cbr%2F%3ERejection+comment:+3.3.2%0D%0A5.+Just+say+to+record+in+the+required+database+as+SP5+will+be+changing+from+paper+soon%0D%0A%0D%0A63.4.2%0D%0A3.+Don't+make+reference+to+P:Drive+-+If+a+standard+is+referred+to+then+it+needs+to+be+in+a+standard+form%0D%0A+%7C'&%40CheckInType=0"
As you can see, there’s a query string send using odata format, that contains check in comment. I have highlighted the part that causes the problem. The single quote, that is not escaped is actually prematurely ending the “Comment” param (marked with purple). So that, all that is after the single quote in “Don't
” is actually not meeting required odata format and causes the issue.
Solution
The most proper solution is to simply replace the action “Check in item” action with the “Office 365 Check in items” one.
Important! If you are using other actions to check out, check in, set approval status etc… be sure you are using them all from a single group. So either regular ones or from the “Office 365” group. If not, you can face another issue, that eg. file is locked for editing by the same account that is executing the workflow, because it checked the file out with regular action and now is trying to check it in with Office 365 one. Somehow SharePoint thinks those are two different accounts.
Other solution is to use “Regular Expression” action and to replace & and ‘ with their counterparts: & (FULLWIDTH AMPERSAND, source) and ` (back quote, it’s below tilde). Then to use such “escaped” string as a comment in “check in item action.