Power Automate技术问询:如何为SharePoint列表中每批来自ATSUB邮件的项生成ATSUB#与ATT#自动编号
Hey there! Let's walk through how to build this automatic numbering system for your SharePoint list, tailored to your ATSUB email and attachment workflow.
Core Requirements Recap
First, let's make sure we're aligned on what you need:
- A unique
ATSUB#XXXX(4-digit sequential number) for each incoming ATSUB email with PDF attachments - One SharePoint list item per PDF attachment, sharing the same
ATSUB#as the parent email - Sequential sub-numbering for attachments in the same email:
ATT#XXXX-YY(YY is a 2-digit number starting at 01) - Your list already has columns:
ATSUB#,ATT#,Email ID,Attachment ID
Recommended Solution: Power Automate (Microsoft Flow)
This is the most reliable way to handle email triggers, number generation, and list item creation. Here's a step-by-step breakdown:
Step 1: Set Up the Email Trigger
- Create a new Automated cloud flow in Power Automate
- Choose the trigger: When a new email arrives (V3) (using the Office 365 Outlook connector)
- Configure trigger filters to target only your ATSUB emails:
- Set Subject contains to
ATSUB - Check Has attachments to
Yes - (Optional) Add a filter for Attachment name ends with
.pdfto pre-filter attachments
- Set Subject contains to
Step 2: Generate the Next ATSUB#
We need to pull the highest existing ATSUB# from your list, increment it, and format it correctly:
- Add a Get items action (SharePoint connector) pointing to your list
- Set Sort by to
ATSUB#, Sort order to Descending, and Top count to1(this grabs the latest record with the highest ATSUB number)
- Set Sort by to
- Initialize a string variable named
NewATSUBID - Add a Condition action to check if the
Get itemsresult is empty (meaning your list has no records yet):- If true (empty list): Set
NewATSUBIDtoATSUB#0001 - If false: Use this expression to increment and format the number:
How this works: It extracts the 4-digit number from the existingconcat('ATSUB#', formatNumber(add(int(substring(body('Get_items')?['value'][0]?['ATSUB#'], 6, 4)), 1), '0000'))ATSUB#, converts it to an integer, adds 1, formats it back to a 4-digit string with leading zeros, then appends theATSUB#prefix.
- If true (empty list): Set
Step 3: Process Attachments & Create List Items
For each PDF attachment in the email, create a list item with the correct ATT#:
- Initialize an integer variable named
AttachmentCounterwith a default value of1(this tracks the sub-number for attachments in the current email) - Add an Apply to each action, selecting the Attachments output from your email trigger
- Inside the loop, add a Condition to check if the current attachment's Name ends with
.pdf(to skip non-PDF attachments)- If true:
- Generate the
ATT#using this expression:concat('ATT#', substring(variables('NewATSUBID'), 6, 4), '-', formatNumber(variables('AttachmentCounter'), '00')) - Add a Create item action (SharePoint connector) and populate the fields:
DATE: Use the email's Received timeATSUB#: Select theNewATSUBIDvariableATT#: Paste theATT#expression you just createdEmail ID: Use the email's ID (from the trigger output)Attachment ID: Use the current attachment's ID (from the loop item)
- Add an Increment variable action to increase
AttachmentCounterby1(so the next attachment gets the next sub-number)
- Generate the
- If true:
Step 4: Test & Refine
- Send a test ATSUB email with 1 or more PDF attachments to verify the flow triggers correctly and creates the right list items
- If you have historical ATSUB emails to process, you can use the Manually trigger a flow option and select existing emails to backfill your list
Key Notes
- Make sure your Power Automate account has permissions to read emails from your Outlook inbox and edit the SharePoint list
- Set the
ATSUB#column in SharePoint to Unique to prevent duplicate numbers (this acts as a safety check if the flow runs unexpectedly) - If your list has a large number of existing records, double-check that the
Get itemsaction correctly pulls the highestATSUB#(you might need to adjust the filter if you have older entries with non-standard formatting)
内容的提问来源于stack exchange,提问作者VeeEss
相关产品推荐
相关产品推荐

