Tried to make a flow on Microsoft automate, need help fixing the errors below:
1. Trigger: When a file is created
Click + New flow → Automated cloud flow.


Choose the trigger When a file is created (OneDrive for Business).


Click … on that trigger → Show advanced options.


Folder: click the folder picker and navigate to /Clinic/Research.


Click Save.



2. Get file content
Click + New step.


Search for Get file content (OneDrive for Business).


In File select the dynamic content File Identifier from the trigger.


Click Save.



3. Extract Category (Compose)
Click + New step.


Search for Compose and select it.


Rename the step to Extract_Category.


In Inputs enter your expression or dynamic content that pulls the category from the file name—for example, an expression like:

 last(split(triggerOutputs()?['body/Name'], '_'))  
 (or whatever logic you already have working)


Click Save.



4. List files in Organized folder
Click + New step.


Search List folder (OneDrive for Business).


Folder: pick /Clinic/Research/Organized.


Click Save.



5. Initialize FolderExists variable
Click + New step.


Search Initialize variable.


Name: FolderExists


Type: Boolean


Value: false


Click Save.



6. Apply to each
Click + New step.


Search Apply to each.


Select an output from previous steps → choose value from List folder.


Click Save.



6.1 Inside that loop: Detect Matching Folder
Click + Add an action inside the Apply to each.


Search Condition and add it.


First condition row (ensure it’s a folder):
Left: click Expression → paste

 items('Apply_to_each')?['folder']  
 → OK


Operator: is not equal to


Right: type null


Add second row (click “+ Add” under the first row):
Left: click Expression → paste

 items('Apply_to_each')?['Name']  
 → OK


Operator: is equal to


Right: switch to Dynamic content and click outputs('Extract_Category')


(The UI will automatically AND these two rows.)
 3. Click Save on that condition.

6.2 Inside the If yes branch of that condition: Set variable
Under the If yes box, click + Add an action.


Search Set variable and select it.


Name: FolderExists


Value: true (type it in)


Click Save.


Leave the If no branch empty.

7. After the loop: Check FolderExists
Click + New step (below the entire Apply to each, not inside).


Add another Condition.


Left: click Dynamic content → select FolderExists.


Operator: is equal to


Right: type false


Click Save.



8. If no folder existed → create it & move the file
8.1 In the If yes branch (FolderExists = false): Create folder
Click + Add an action under If yes.


Search Create folder (OneDrive for Business).


Folder Path: /Clinic/Research/Organized


Folder Name: switch to Expression → paste

 outputs('Extract_Category')  


Click Save.


8.2 Then Move the file
Click + Add an action immediately below Create folder.


Search Move file (OneDrive for Business).


File: dynamic content File Identifier from the trigger.


Destination Folder: click Expression → paste

 concat('/Clinic/Research/Organized/', outputs('Extract_Category'))  


Click Save.


Leave the If no branch of this post‑loop condition empty.

9. Save & Test your flow
Click Save in the top right.


Click Test, upload a file to /Clinic/Research whose name’s category folder does and doesn’t already exist.


Observe the run history to confirm:


If the folder existed → FolderExists is set and no new folder is created.


If not → new folder is created and file is moved into it.



Current problems I am having: 
Detect Matching Folder: Checks if a folder with the extracted category name exists.
Issue: The condition expression needs to be updated to use not(equals(items('Apply_to_each')?['folder'], null)).