power-automate

How to get the columns from a Microsoft list row into an array of strings


I'm getting one row from a Microsoft list and want to loop though each column in the row, the problem I'm having is putting each into an array so I can user a loop. All i need is the column names , not the row values.

I know in can access the using the dynamic content but I need to pull a row and it can be different lists.

Does anyone know how it can be done?

Thanks.

I have tried using json and compose but I can't get it for work.


Solution

  • You can do this with xpath.

    Create a new Select action under Data Operations, and set the following:

    From:
    xpath(xml(json(concat('{"body":', outputs('Get_item')?['body'], '}'))), 'body/*')
    Map:
    xpath(item(), 'name(/*)')
    

    This will return a string array of the column names.

    Note: in the Select action, click on the Switch map to text mode button (looks like 🅃 ). Select action


    Alternatively, you can use the following request to get the column names of a list as an array.

    Method: GET
    URI: /_api/web/lists/getbytitle('YOUR LIST NAME')/fields?$filter=Hidden eq false and ReadOnlyField eq false
    

    GET request to get SP List column names