Updating folder names when changing sharepoint list items

Anonymous
2024-05-31T14:19:54+00:00

Hi,

I am currently creating a sharepoint list that tracks employee on-boarding. I already created a flow that creates folders for every employee in a document library, and adds all attached files in those folders. The folders are named after the employees themselves. 

This is a seperate flow that tracks if the names of the employees are changed (due to a spelling error for example).

With the ID and a custom expression, I manged to initialize the variable 'Old Name' using data from the previous version in sharepoint list. Than I use an if condition to check if the column variable 'Medenwerker' has been altered (aka the employee's name). If so, I use a Send HTTP request to try and replace the old folder name with the new folder:

Most of the flow seems to work fine, but during the final step with the HTTP request, the flow takes an unusually long (like 12 minutes) to load before giving up. It keeps saying that "X retries occured". Most of the time it has 2 retries with a "BadGateway" status, and I cant figure out why this happens.

 

So how can I fix this issue? Maybe this isn't even the best way of going about things (ideally, it tracks other kinds of changes like removed attachments as well), so suggestions are very welcome!

Sincerely,

Jelmer

Microsoft 365 and Office | SharePoint | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Anonymous
    2024-06-01T06:54:33+00:00

    Dear Jelmer,

    You may use API to get the previous of the item value and then update the folder by the folder id to move forward.

    Get all versions of the EmployeeName values.

    _api/web/lists/GetByTitle('ListforEmployee')/items(@{triggerOutputs()?['body/ID']})/Versions?$select=EmployeeName

    Compose to get the previous value of EmployeeName.

    outputs('Send_an_HTTP_request_to_SharePoint_')?['body']?['d']?['results'][1]?['EmployeeName']

    Find the folder id of the folder which needs to be updated.

    items('Apply_to_each')?['ID']

    Update the folder name by _api/web/lists/GetbyTitle('Library for Emplyee')/items(@{outputs('Compose_3')})/validateUpdateListItem with the method POST.

    Body:

    {

    "formValues": [

    {
    
      "FieldName": "FileLeafRef",
    
      "FieldValue": "@{outputs('Compose\_2')}"
    
    }
    

    ]

    }

    List:

    Library:

    Flow Details:

    Thank you for your effort and time.

    Sincerely

    Cliff | Microsoft Community Moderator

    0 comments No comments
  2. Anonymous
    2024-06-06T14:58:12+00:00

    Hi,

    First off, thank you for the elaborate response. Really appreciated.

    Secondly, there seems to be something wrong with the filtering step. This is how the filter is set up.

    Image

    When running the flow, you can see that it grabs the old name and the new name fine:

    But when creating the filter array, it remains empty:

    Image

    How should I go about filtering?

    Sincerely,

    Jelmer

    0 comments No comments
  3. Anonymous
    2024-06-07T04:52:53+00:00

    Dear Jelmer,

    Thanks for your updates and kindness.

    The filter formula should be correct.

    Please go to the site library to check whether the folder with the old name exists. If no, the filter action will not find the folder and the output will be shown as [ ].

    Welcome to share any updates at your convenience.

    Thank you for your effort and time.

    Sincerely

    Cliff | Microsoft Community Moderator

    0 comments No comments
  4. Anonymous
    2024-06-07T08:04:25+00:00

    I have tried changing a name in the sharepoint list. It seems to register everywhere and in my flow it depicts the old name and new name correctly, but the filter remains empty and I don't see any changes in the sharepoint library (I have also ensured that I am in the right document. Maybe it has to do with the Get files property? Do I need to be inside the folder that I want to change? Or do I need to be in the folder containing that folder (like I am currently doing)?

    Jelmer

    0 comments No comments
  5. Anonymous
    2024-06-08T04:10:55+00:00

    Dear Jelmer,

    Thanks for your updates.

    No, you don't need to do that. The Get Files action gets all files and folders in the library no matter it is a file or a folder. It finds the files and folders based on the item id.

    From your previous posts, your aim is to update the corresponding root folder name in the library when a item name is updated in the list.

    For example, before running the flow, the list item name should match the library folder name.

    If I change usernewtest1 to userB, the folder usernewtest1 should be automatically updated to the folder userB after the new run is executed on the flow.

    So please check whether the list item name matches the library folder name before triggering the flow.

    Welcome to share any updates at your convenience.

    Thank you for your effort and time.

    Sincerely

    Cliff | Microsoft Community Moderator

    0 comments No comments