cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MajorOfSweden
Frequent Visitor

Dynamically set reference type for Planner attachments

I’m working on a automation that will trigger by filling a Forms and create a planner task. The automation will add files to the task from a SharePoint folder and I’ve successfully done it with “hardcoding” the files I want to add but I would prefer to have it dynamic since the files I add will most likely change over time.

 

Right now I can add files dynamically but one thing I can’t seem to solve is how to add Reference type dynamically i.e if I add a PDF file the reference type will be set to PDF and so forth. 

1 ACCEPTED SOLUTION

Accepted Solutions
MajorOfSweden
Frequent Visitor

I've been working on this tonight and actually solved it even if it's maybe not the most effective way.
I started with using Compose and insert a JSON formatted array with the file types and their corresponding reference types.

[
  {
    "id": 1,
    "file_type": "pdf",
    "reference_type": "Pdf"
  },
  {
    "id": 2,
    "file_type": "ppt",
    "reference_type": "PowerPoint"
  },
  {
    "id": 3,
    "file_type": "pptx",
    "reference_type": "PowerPoint"
  },
  {
    "id": 4,
    "file_type": "xls",
    "reference_type": "Excel"
  },
..............

I then used a Array filter like this:
Skärmbild 2021-09-23 052247.png

indexOf(outputs('Copy_file')?['body/Path'], item()?['file_type'])

From here I add the corresponding reference type into my file array using:

Skärmbild 2021-09-23 052837.png

first(body('Filtermatris_2'))?['reference_type']

 I then use my file array to add references (attachments) to my planner task:
Skärmbild 2021-09-23 053127.png

All this is inside a Apply to each that goes through all files in a specified SharePoint folder.

View solution in original post

4 REPLIES 4
manuelstgomes
Super User
Super User

Hi @MajorOfSweden 

 

To do that, you need to build the entire array yourself. It's not complex, and you can check the structure by doing a test value. For example,

Screenshot 2021-09-22 at 12.04.21.png

When you press the "Switch to input the entire array", you'll get this.

Screenshot 2021-09-22 at 12.04.26.png

 

I wrote an article explaining how to add attachments to the email, but the concept is precisely the same. You can find it here:

https://manueltgomes.com/microsoft/powerautomate/power-automate-add-attachment-to-e-mail-dynamically...

 

The idea is to generate the JSON in an array variable and then use the join function to generate the final value.

 

Can you please take a look at the strategy and see if it solves your problem?

 

Cheers
Manuel

------------------------------------------------------------------
If I have answered your question, please mark it as "Accept as Solution." It will help other members finding the solution faster. If you like my response, please give it a Thumbs Up. ?
Otherwise, reply to it, and the community will do its best to help you.

E6B71FD2-CE36-4A43-83C0-702AB8E6D4FF.jpeg

5FD52B76-9861-4206-BF5D-BBE533D80BA1.jpeg

  

Hi @manuelstgomes !

 

Maybe my original post was a bit unclear since I wrote it after working a night shift. What to linked in your answer I’ve already accomplished using your article actually. The problem is that if I attach a PDF file planner won’t recognize it as PDF, it’s only recognized as a link to the SharePoint. My organization uses Planner through Teams desktop so it would be neat to have the most common file formats recognized so they can be opened within teams rather than opening the link in a web browser.

I did manage to get it working for one file type using an array that iterates through all files in folder and use an If statement to look for “pdf” in file name and use return value as reference type. I would like to build on that to take more file types. See attached images.

MajorOfSweden
Frequent Visitor

I've been working on this tonight and actually solved it even if it's maybe not the most effective way.
I started with using Compose and insert a JSON formatted array with the file types and their corresponding reference types.

[
  {
    "id": 1,
    "file_type": "pdf",
    "reference_type": "Pdf"
  },
  {
    "id": 2,
    "file_type": "ppt",
    "reference_type": "PowerPoint"
  },
  {
    "id": 3,
    "file_type": "pptx",
    "reference_type": "PowerPoint"
  },
  {
    "id": 4,
    "file_type": "xls",
    "reference_type": "Excel"
  },
..............

I then used a Array filter like this:
Skärmbild 2021-09-23 052247.png

indexOf(outputs('Copy_file')?['body/Path'], item()?['file_type'])

From here I add the corresponding reference type into my file array using:

Skärmbild 2021-09-23 052837.png

first(body('Filtermatris_2'))?['reference_type']

 I then use my file array to add references (attachments) to my planner task:
Skärmbild 2021-09-23 053127.png

All this is inside a Apply to each that goes through all files in a specified SharePoint folder.

View solution in original post

manuelstgomes
Super User
Super User

Hi @MajorOfSweden 

Looks good! Well done. 😀

If you can't finish for some reason, please let me know.

Cheers
Manuel

------------------------------------------------------------------
If I have answered your question, please mark it as "Accept as Solution." It will help other members finding the solution faster. If you like my response, please give it a Thumbs Up. ?
Otherwise, reply to it, and the community will do its best to help you.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (3,056)