Skip to main content

Fixed: "Invalid Field Name" BadGateway When Removing a Column from a SharePoint View in Power Automate

· 11 min read
Jagdish Kumawat
Founder @ Dewiride

I ran my setup flow a second time to prove it was safe to run again. Instead of finishing in seconds, it sat on Waiting for half an hour, then failed: Action 'Remove_Title_from_the_view' failed: BadGateway. Behind the 502 was SharePoint saying Invalid field name. The first run had already removed that column from the view, and asking again was an error that Power Automate retried for minutes at a time.

What I Was Doing​

The setup flow in Part 11 of the Career Development Plan series creates two SharePoint lists and their columns. A list created with the REST API shows its Title column in the default view, so one step, Remove Title from the view, takes it out with this request (How to Hide the Title Column of a SharePoint List with the REST API explains it):

Uri
_api/web/lists/getbytitle('@{items('For_each_list')?['title']}')/defaultview/viewfields/removeviewfield('LinkTitle')

LinkTitle is the name SharePoint gives the Title column in a view. While I built the flow, I ran it several times on an empty test site. The last of those runs, at 1:45 PM, was the first with every step: it hid Title on both lists and added all their columns, in 16 seconds. Then I ran the flow again on the same site, at 1:48 PM, to check that a second run changes nothing.

What I Expected​

Another quick run, with every Create step skipped because the lists and columns already existed.

What I Got​

The run didn't finish. Eight minutes in, the run view showed For each list and every step inside it as Waiting, and Find the list, the loop's first step, had no status at all:

The running flow with Your flow is running…, the trigger, List definitions and Check the site succeeded, and For each list at 1 of 2 with Find the list, If the list is missing and Update the list settings all showing a waiting circle, and Find the list's Status Not specified

After 20 minutes, I selected Cancel in the run view. Nothing changed, so I also ticked the run in All runs and selected Cancel flow run(s), the way Microsoft's cancel and resubmit article describes:

The Run history page with the 1:48 PM run ticked, Test running after 23 minutes, and Cancel flow run(s) outlined in red

The run wasn't canceled. After 28 minutes and 48 seconds it ended by itself, as Test failed, with Flow run failed. Action 'Remove_Title_from_the_view' failed: BadGateway. The step had taken 14 minutes 32 seconds, and its pane said 2 retries occurred:

The failed run with the banner Flow run failed. Action 'Remove_Title_from_the_view' failed: BadGateway, the step's pane showing 2 retries occurred and BadGateway, and the card Remove Title from the view at 14m 32s with For each column skipped below it

A second run, started at 2:14 PM before I found the cause, also failed, after 24 minutes.

What I Checked​

  1. Whether Microsoft had an outage. Service health in the Microsoft 365 admin center showed Power Automate and SharePoint Online as healthy, and the Power Platform admin center's Service health reported no issues.

  2. Microsoft's Troubleshoot slow running flows. It lists a slow service, connector throttling and plan limits. None fit a flow that had run a handful of times that day, the last time in 16 seconds.

  3. The loop's settings. Concurrency control was off, so the loop ran its items one after another, the default.

  4. The failed step's outputs, once the run had ended. Its Run results showed status code 502, and these fields in the body, with the request IDs masked:

    Error fields from the step's outputs
    error.code 502
    error.message BadGateway
    error.innerError.status 502
    error.innerError.message {"odata.error":{"code":"-2146232832, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"Invalid field name."}}}
    error.innerError.source https://contoso.sharepoint.com/sites/CareerDevelopmentPlanTest/_api/web/lists/getbytitle('RoleCompetencies')/defaultview/viewfields/removeviewfield('LinkTitle')

    So the 502 wasn't a gateway problem: SharePoint had refused the request with Invalid field name.

  5. The step's Retry history. The first attempt ran at 1:48:13 PM and the retry at 1:53:15 PM, five minutes later. Both failed with BadGateway in about a second. The last attempt ended at 2:02:45 PM, about ten minutes after that:

    The step's Retry history tab at 2 of 2, showing a retry that lasted 1.3 seconds, started at 1:53:15 PM and failed with BadGateway

    Microsoft's limits article explains the timing. For flows on the Low performance profile, which covers Microsoft 365 licenses, the default retry policy sends up to two retries, at intervals that grow in steps of 5 minutes up to about 10. Microsoft's error handling article says requests are retried when they fail with a 408, 429 or 5xx response. A 502 is a 5xx, so each list waited about 14 minutes for an error that was never going to go away.

  6. The view. A GET request to the list's defaultview/viewfields returned the view's columns in Items, and LinkTitle wasn't one of them. The 1:45 PM run had removed it. Microsoft's reference for removing a field from a view only describes the method. It doesn't say what happens when the field isn't in the view. SharePoint's answer was Invalid field name.

  7. The run view. Once the run had ended, Find the list and the steps after it showed real times: they had all succeeded at 1:48 PM. While the loop was still running, the run view had shown them as Waiting.

Why It Happens​

removeviewfield works only when the column is in the view. On a second run, the run before it had already removed Title, so SharePoint refused the request. The connector reported that as a 502, and Power Automate retried it twice, minutes apart, before failing the step. That took about 14 minutes for each of the two lists, while the run view showed the loop as Waiting.

The Fix​

Check the view before removing the column, the same way the flow already checks for a list and a column before creating them.

  1. Add a Send an HTTP request to SharePoint action, Find Title in the view, just before the removal. It reads the view's columns:

    Uri
    _api/web/lists/getbytitle('@{items('For_each_list')?['title']}')/defaultview/viewfields
  2. Add a Condition, If Title is in the view, that checks whether those columns include LinkTitle, and compare it with true (How to Check Whether an Array Contains a Value):

    Expression
    contains(body('Find_Title_in_the_view')?['Items'], 'LinkTitle')

    The If Title is in the view pane with the condition contains(...) is equal to true

  3. Move Remove Title from the view into the condition's True branch. I copied it there and deleted the original (How to Copy and Paste an Action):

    The flow with Hide Title in display forms, then Find Title in the view, then If Title is in the view with Remove Title from the view in its True branch and nothing in False, then For each column

  4. Save the flow.

After the Fix​

The next run on the same site took 8 seconds and succeeded. Remove Title from the view was skipped, along with every Create step:

The finished run with Find Title in the view succeeded, If Title is in the view succeeded with Remove Title from the view skipped in its True branch, and For each column succeeded with Create the column skipped

To test the other branch, I put Title back into the list's view with SharePoint's own Show or hide columns, and ran the flow again. It took 8 seconds too, and Title was out of the view afterwards. The run history tells the story:

The run history with the 2:39 PM and 2:34 PM runs succeeded in 8 seconds, the 2:14 PM and 1:48 PM runs failed after 24 and 28 minutes, and the 1:45 PM run succeeded in 16 seconds

Common Mistakes​

MistakeWhat happensDo this instead
Removing a view column without checkingThe second run fails after long retriesRead defaultview/viewfields first
Waiting for a run that shows WaitingUp to 15 minutes per failed stepCheck the steps' retry history once the run ends
Trusting the 502You look for a network problemRead error.innerError.message

Troubleshooting​

SymptomLikely causeFix
A loop shows Waiting for many minutesA step inside it is being retriedWait for the run to end, then read that step's Retry history
Invalid field name. from removeviewfieldThe column isn't in the viewCheck Items in defaultview/viewfields first
Cancel doesn't stop the runCanceling can take timeMicrosoft's article allows up to 24 hours for bulk cancel; my run ended first

FAQ​

Why was it a 502 and not a 400?​

The Send an HTTP request to SharePoint connector returned 502 BadGateway, with SharePoint's own error inside it. Read the inner error, not just the status.

Could I turn the retries off instead?​

Microsoft's error handling article describes a None retry policy that doesn't resend the request, so the step would fail at once. But it would still fail. Checking first means it never has to.

Do the other Title steps have the same problem?​

No. Making Title optional and hiding it from the forms set a value, and setting the same value twice is fine. Both runs after the fix ran those steps without errors.

Conclusion​

A REST call that removes something fails if it's already gone, and Power Automate retries that failure for minutes at a time on a Microsoft 365 license. Check first: read the view's Items, and remove LinkTitle only when contains() finds it. The flow is then safe to run as often as you like.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.