cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Change date format data from Parse JSON and add removed leading zeros from phone numbers

In the flow below - explicitly around the Parse JSON and 'Update file properties 2' actions, leading zero's (0) are being removed from the telephone fields in my CSV files. This same behaviour is seen when opening the filled CSV files in Excel.

 

Additionally dates are not formatting correctly. For example we're happy for users to enter dates into the CSV templates as eg. 23.01.2023 however in the generated Word document, we want these to appear as '23 January 2023'.

There is also a separate date field in the document where it wants the MONTH and YEAR of installation - so, in the CSV our users are entering August 2023 however the flow is putting this in as Aug 23 - we want it to read as 'August 2023'.

 

Phone numbers should be in this format: 01934123456 however these are having their leading zero's removed so that they read as 1934123456 instead!

 

I am thinking something should be done around @{items('Apply_to_each_2')['Date Letter Created']} to somehow format the date ?

 

and similar for landline or mobile: @{items('Apply_to_each_2')['Sender''s Landline']} ?

 

For reference, this is my Power App:

When the app has loaded, this screen is presented with the list of available document templates to be used. 
In this example, I am using the letter template 'Planned Works Introduction Windows and Doors.docx'.

Once I've chosed a template, I click NEXT >>

sudosaurus_0-1674505801956.png

On the next page, it shows the document details on the left and a button to 'Download CSV Template'.
I fill out the CSV file with the required data.


Then I upload the CSV file (right), followed by clicking on the 'Generate' button.

I am then navigated to another screen advising the letters are now being generated and will be notified once complete.

This is what triggers my below workflow.

sudosaurus_1-1674505879744.png

 

 

This is my flow below for reference >>>


PowerApps is triggering the flow:

sudosaurus_0-1674491283518.png

Next we are getting the user profile of the person who initiated the PowerApps flow:

sudosaurus_1-1674491388754.png

Next we are creating an item in the 'Bulk Doc Tracker' SharePoint list with the Display Name
and Mail attributes of the user - this will be used later to email the user confirming that the 
workflow was successul with a link to their documents that had been generated:

sudosaurus_3-1674494941676.png

Next we are using the Initialize variable action to Initalize RAW CSV Data:

sudosaurus_4-1674494979261.png

Next we are using the HTTP  action to post the output of the above action to our bulk document generator json Azure site:

sudosaurus_5-1674495102736.png

Next we use the Compose action to compose the Body outputs of the previous action:

sudosaurus_6-1674495216595.png

Now we Parse JSON from the Outputs of the JSONArray:

sudosaurus_7-1674495265139.png

Schema details:

 

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "Equipment Type": {},
            "Internal External Decoration or Cleaning": {},
            "Type of Heating System": {},
            "Consultant’s Name": {},
            "LiveWest Tenant Liaison Officer": {},
            "Address Line 3": {},
            "Contractor’s Contact": {},
            "Current Financial Year Of Planned Upgrade": {},
            "Team Name": {},
            "Project Name": {},
            "Contractor or Operative": {},
            "Name of LiveWest Member of Staff": {},
            "LiveWest Contact Date 2": {},
            "Contractor’s Number": {},
            "Survey or Install": {},
            "Installing/Fitting A New/Installing New": {},
            "Description of Works Required": {},
            "Regulations Year for Scheme": {},
            "Date Heating Upgrade Works Will Be Carried Out Before": {},
            "Windows Or Windows and Doors": {},
            "Address Line 5": {},
            "LiveWest Project Manager": {},
            "Customer Name": {},
            "Month and Year of Works to be Completed": {},
            "Date When Appointment Was Agreed": {},
            "Property Reference": {},
            "Kitchen Or Bathroom": {},
            "Contractor Date 2": {},
            "Team Email Address": {},
            "Address Line 4": {},
            "Energy Supplier Name": {},
            "Date Letter Created": {},
            "Work Type Approved": {},
            "Address Line 2": {},
            "Asset Address": {},
            "Date Letter Valid until": {},
            "Dates for Contact Attempts": {},
            "Month of Works to be Completed": {},
            "LiveWest Contact Date 1": {},
            "Contractor’s Email Address": {},
            "Year of Works to be Completed": {},
            "Properties Roads or Estates": {},
            "Date of Letter Plus 30 Days": {},
            "LiveWest Tenant Liaison Officer’s Contact Number": {},
            "ServiceType": {},
            "Month Of Planned Installation": {},
            "LiveWest Contact Date 3": {},
            "Address Line 1": {},
            "Financial Year of Planned Upgrade": {},
            "LiveWest Project Manager’s Contact Number": {},
            "Contractor’s Contact Number": {},
            "Boiler Radiators or Central Heating": {},
            "Financial Year of Chimney Sweep": {},
            "Contractor Name": {},
            "Check Contractor’s Name": {},
            "Name of Surveyor": {},
            "Air Source Heat Pump or Gas Central Heating": {},
            "Team Contact Number": {},
            "Street or Estate of Address": {},
            "CDM Advisor": {},
            "Type of Key to Be Cut": {},
            "6 or 12 months": {},
            "Deadline For Customer Response": {},
            "Appointment/Visit Date and Time": {},
            "Component to be Replaced": {},
            "Next Financial Year Of Planned Upgrade": {},
            "Contractor Date 1": {},
            "Start Date For Planned Works": {},
            "Sender's Job Title": {},
            "Sender's Name": {},
            "Sender's Mobile": {},
            "Sender's Landline": {},
            "Sender's Email": {},
            "Receiver's Name": {},
            "Key Type Make and Serial Number": {},
            "Installation Type Boiler Kitchen Bathroom or Windows": {}
        },
        "required": [
            "Asset Address",
            "Installation Type Boiler Kitchen Bathroom or Windows",
            "LiveWest Tenant Liaison Officer",
            "Address Line 2",
            "Boiler Radiators or Central Heating",
            "Team Email Address",
            "ServiceType",
            "Customer Name",
            "Contractor Date 2",
            "Sender's Job Title",
            "Financial Year of Planned Upgrade",
            "Property Reference",
            "Contractor Date 1",
            "Sender's Mobile",
            "Properties Roads or Estates",
            "Internal External Decoration or Cleaning",
            "Energy Supplier Name",
            "Contractor’s Email Address",
            "Component to be Replaced",
            "Type of Key to Be Cut",
            "Description of Works Required",
            "Sender's Email",
            "Date Letter Valid until",
            "Month Of Planned Installation",
            "Financial Year of Chimney Sweep",
            "Address Line 4",
            "Check Contractor’s Name",
            "Installing/Fitting A New/Installing New",
            "Name of Surveyor",
            "Name of LiveWest Member of Staff",
            "Address Line 3",
            "Key Type Make and Serial Number",
            "Current Financial Year Of Planned Upgrade",
            "CDM Advisor",
            "Date Heating Upgrade Works Will Be Carried Out Before",
            "Address Line 5",
            "Team Name",
            "Contractor’s Number",
            "Next Financial Year Of Planned Upgrade",
            "Regulations Year for Scheme",
            "Dates for Contact Attempts",
            "Date When Appointment Was Agreed",
            "LiveWest Contact Date 2",
            "Kitchen Or Bathroom",
            "Sender's Landline",
            "Year of Works to be Completed",
            "Sender's Name",
            "Type of Heating System",
            "Appointment/Visit Date and Time",
            "Address Line 1",
            "Month and Year of Works to be Completed",
            "Street or Estate of Address",
            "Contractor or Operative",
            "Windows Or Windows and Doors",
            "Start Date For Planned Works",
            "Team Contact Number",
            "Deadline For Customer Response",
            "LiveWest Tenant Liaison Officer’s Contact Number",
            "Survey or Install",
            "LiveWest Contact Date 1",
            "Receiver's Name",
            "Date of Letter Plus 30 Days",
            "Air Source Heat Pump or Gas Central Heating",
            "LiveWest Contact Date 3",
            "Month of Works to be Completed",
            "Contractor Name",
            "Contractor’s Contact",
            "Date Letter Created",
            "LiveWest Project Manager",
            "Work Type Approved",
            "Consultant’s Name",
            "6 or 12 months",
            "LiveWest Project Manager’s Contact Number",
            "Contractor’s Contact Number",
            "Project Name",
            "Equipment Type"
        ]
    }
}

 

 

Next we Get file content using path (from PowerApps):

sudosaurus_8-1674495404398.png

Next we Get file metadata using path (from PowerApps):

sudosaurus_9-1674495461142.png

Now we Get file properties of the associated letter that matches the CSV template:

sudosaurus_11-1674495539200.png

Next we start our Apply to each which includes a Scope of several actions - this is where our documents are created and are populated with the details fromt he CSV file generated in PowerApps:

sudosaurus_12-1674495628873.png

The first action in our scope, we are creating a temporary document in the SharePoint Saved Letters folder.
With the Name of the document separated with an underscore followed by the Property Reference number that was included in the CSV file:

sudosaurus_13-1674495675275.png

Next we are updating the file properties with the text data from the CSV file into QuickPart placeholders in the word document:

This is the step where the incorrect date formats are being applied to the Word document as well as the telephone and mobile numbers not being added with a prefixed '0'. I believe the Parse JSON step is removing the leading zeros from the CSV file.

sudosaurus_15-1674495773917.png

Next we get the file content of the document that was just created:

sudosaurus_17-1674495867022.png

Next we create a copy of this file in OneDrive:

sudosaurus_18-1674495883574.png

Now we convert this copied file into a PDF document:

sudosaurus_19-1674495902853.png

Next we create a copy of the PDF file back into the SharePoint Saved Letters folder:

sudosaurus_20-1674495929844.png

Next we create a second copy into the PrintLetters folder:

sudosaurus_21-1674495975536.png

Finally we create a 3rd copy in the CxDocuementInbox folder (this is our record centre):

sudosaurus_22-1674496040608.png

Next we update the Control Term (document type) of the document so that our Record Centre
knows where to file it.

sudosaurus_23-1674496079603.png

Next we have a condition that checks whether the document/letter has an accompanying document, eg. a flyer / static information etc.

sudosaurus_24-1674496112045.png

If one is required, we then Get Accompanying document content using path

Then we create the Accompanying document in the Print Folder (as these have to be printed with letters from our offsite commercial printing firm). 

sudosaurus_25-1674496173057.png

Next we delete the earlier created temporary PDF file in OneDrive:

sudosaurus_26-1674496195423.png

Next we delete the earlier created temporary DOC file in SharePoint:

sudosaurus_27-1674496206426.png

Lastly, we use the Update item action to make the Status Value in the Bulk Doc Tracker list as 'Complete'.
This then triggers another workflow that sends an email to the user advising that their letters have been generated.

sudosaurus_29-1674496263849.png

 

If you have any questions, please do ask! 

Appreciate any help given 🙂



If I helped you solve your problem - please mark my post as a solution and consider giving me a like if you liked my response!

If you're feeling generous you can Buy me a coffee: https://www.buymeacoffee.com/sudosaurus
7 REPLIES 7

For your leading zeros, if you always want to have 11 digits that make up the phone number then you can use the following expression.

//If your phone numbers are coming back as raw numbers
formatNumber(YOUR_FIELD, '#00000000000')

//If your phone numbers are coming back as a string of numbers
formatNumber(int(YOUR_FIELD), '#00000000000')

 

For your date that comes back as Aug 2022 for example, you can just use formatDateTime to get what format you want. See expression below that would return August 2022 in this instance.

formatDateTime(YOUR_FIELD, 'MMMM yyyy')

 

The date that's entered as 23.01.2023 is a bit trickier since the datetime string must match ISO 8601 format which this doesn't. It will throw an error if you try to use formatDateTime. I'd suggest making sure users enter the dates in the appropriate format, but know that's difficult when entering directly into Excel/CSV, etc. You're always going to be prone to errors in the flow if there's no control of the format used unfortunately.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

@grantjenkins I'm assuming that the 24/01/2023 format would work ok?



If I helped you solve your problem - please mark my post as a solution and consider giving me a like if you liked my response!

If you're feeling generous you can Buy me a coffee: https://www.buymeacoffee.com/sudosaurus

@grantjenkins 

I am seeing this error when running my flow.

InvalidTemplate. Unable to process template language expressions in action 'Update_file_properties_2' inputs at line '0' and column '0': 'The template language function 'formatDateTime' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#formatdatetime for usage details.'.

 These are the two types of expressions I'm using:

formatDateTime(items('Apply_to_each_2')['Start Date For Planned Works'], 'MMMM yyyy')
formatNumber(items('Apply_to_each_2')['Sender''s Landline'], '#00000000000')

 



If I helped you solve your problem - please mark my post as a solution and consider giving me a like if you liked my response!

If you're feeling generous you can Buy me a coffee: https://www.buymeacoffee.com/sudosaurus

It looks like not everyone is filling in those values which is why some of them are coming back as null. To get around this, you can check to see if there is a value - if there is then use the expression, otherwise just set as null.

 

if(empty(items('Apply_to_each_2')['Sender''s Landline']), null, formatNumber(items('Apply_to_each_2')['Sender''s Landline'], '#00000000000'))

if(empty(items('Apply_to_each_2')['Start Date For Planned Works']), null, formatDateTime(items('Apply_to_each_2')['Start Date For Planned Works'], 'MMMM yyyy'))

----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Do you have some sample JSON output you get that shows the dates you are getting back?


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

@grantjenkins 

 

[
  {
    "Date Letter Created": "24/01/2023",
    "Month Of Planned Installation": "08/2023",
  }
]


If I helped you solve your problem - please mark my post as a solution and consider giving me a like if you liked my response!

If you're feeling generous you can Buy me a coffee: https://www.buymeacoffee.com/sudosaurus

If the dates are only ever going to be in the formats shown below (two objects):

[
  {
    "Date Letter Created": "24/01/2023",
    "Month Of Planned Installation": "08/2023"
  },
  {
    "Date Letter Created": "24.2.2023",
    "Month Of Planned Installation": "08.2023"
  }
]

 

Then you might be able to get around the invalid dates using the following expressions. The first one is quite convoluted. I'll do some more research to see if there's an easier way to handle dates like this.

//Date Letter Created
formatDateTime(concat(split(replace(item()?['Date Letter Created'], '.', '/'), '/')[2], '-', split(replace(item()?['Date Letter Created'], '.', '/'), '/')[1], '-', split(replace(item()?['Date Letter Created'], '.', '/'), '/')[0]), 'dd MMMM yyyy')

//Month Of Planned Installation
formatDateTime(item()?['Month Of Planned Installation'], 'MMMM yyyy')

 

grantjenkins_0-1674721716487.png

 

Outputs

grantjenkins_1-1674721752851.png

 


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,545)