Forum Discussion
ScottEQ
Dec 14, 2023Copper Contributor
Sharepoint Designer 2013 Looping and Looping Emails
I am trying to automate a process within my business and would like to see if this would even be possible in the way that I have envisioned.
One of the things my team handles. Is our businesses domain estate. Our domains have a listed "Business owner" from inside the business. Every month we need to reach out to those business owners where a domain is coming up for expiry to ascertain if the respective domain is to be renewed or not.
I have setup a SharePoint list, key fields being the domain, expiry date, 60 days from expiry and 30 days from expiry.
I was looking to run a few daily workflows that check on the 60 days and 30 days column and send an email to the business owner to attain renewal status (Renew yes/no).
One of the things is, we have multiple domains with the same business owner. So I would like to try and refrain from sending a person multiple emails per domain and try and collate all domains expiring around the same time in to one email.
So, I would like to try and loop through my list, locate the domains expiring within 60 days take all the domains with the same business owner and email that person at once, listing each domain in the email.
I don't know if I have used the correct process. But at the moment, I have the following:
Stage 1
If CurrentItem: 60 Days remaining equals Today
Loop: 1
The content of this loop will run repeatedly while: CurrentItem:Email Group equals Group 1
(i have gone through my list and added Group 1, 2, 3, etc.. where we have domains listed against the same business owner. So, all domains by Joe Blogs has Group 1, all domains by John Doe are Group 2, etc..)
Build Domains Dictionary (Output to Variable: Domains)
Then Build Expiry Dictionary (Output to Variable: Expiry)
Then Email CurrentItem: Business Owner Email Address
I will then do another loop for Email Group equals Group 2, then Group 3, etc..
The point where I am stuck, is trying to build the email and ensure that I list each domain and the expiry date in an eligible way. Rather than just listing the string of domains as a string and then the expiry dates as a string, with no real correlation between what domain has which expiry date.
Any input would be appreciated!
Few things to note: I have to use SharePoint Designer 2013. The SharePoint list i am working with does not have access to be used with PowerAutomate 😞
Thanks for taking the time to read all this!
1 Reply
Sort By
- BarryGoblonIron Contributor
ScottEQ Based on my experience, I recommend structuring the email body using an HTML table for a more organized presentation. Start by creating two columns in the table, with the first one dedicated
to listing domain names and the second one to display their respective expiration dates. This approach significantly enhances the clarity of the domain-to-date mapping, providing a readable format that simplifies understanding.
When constructing the domain and expiration dictionaries, I suggest opting for a more efficient approach by using arrays for each variable rather than relying on a long string.
For instance:
<script>
Domains = ["Domain1", "Domain2", "Domain3"];
Expiry = ["1/1/2023", "1/15/2023", "2/1/2023"];
</script>In the email body, iterate over these arrays using a counter variable to dynamically print each domain and its corresponding expiration date on a new row within the table:
<script>
for (var i = 0; i < Domains.length; i++) {
document.write("<tr>");
document.write("<td>" + Domains[i] + "</td>");
document.write("<td>" + Expiry[i] + "</td>");
document.write("</tr>");
}
</script>An alternative approach, drawing from my own experience, involves constructing the dictionary with key/value pairs for better manageability:
<script>
DomainsExpiryMap = {"Domain1": "1/1/2023", "Domain2": "1/15/2023", "Domain3": "2/1/2023"};
</script>You can then seamlessly print these pairs in a table using key and value references:
<script>
for (var domain in DomainsExpiryMap) {
document.write("<tr>");
document.write("<td>" + domain + "</td>");
document.write("<td>" + DomainsExpiryMap[domain] + "</td>");
document.write("</tr>");
}
</script>