Skip to main content

Notifications

Power Automate - General Discussion
Answered

Error using FORMAT in CREAT CSV TABLE

(0) ShareShare
ReportReport
Posted on by 294

I am trying to format a few number fields (only starting with one so far) from JSON data brought in. I PARSE JSON to get the fields to use in the subsequent actions. I then use the FORMAT NUMBER action to get the number into Currency format. I then want to use that formatted field in my output when issuing the CREATE CSV TABLE action. But I get the error below. I am lost on how to do this. Any help would be great. Thanks!

 

Error:

(x) Flow save failed with code 'invalidTemplate' and message The template validation failed: 'The inputs of template action 'Create_CSV_table' at lire 1 and column '3984' is Invalid. Action 'Apply_to_each' must be a parent 'foreach' scope of actior 'Create_CSV_table' to be referenced by 'repeatltems' cr 'items' functions.'.'.

 

My flow:

dBrand_0-1619554617278.png

 

  • David Brandman Profile Picture
    David Brandman 294 on at
    Re: Error using FORMAT in CREAT CSV TABLE

    @NiloferA This worked!!! Thanks for sticking in there. Should be easier to do than they make it, but I guess MS will improve it as time goes on. Now I need to format more fields (like a dozen of them). This will be a pain. Hope that goes better, now that I have the rest working. THANKS AGAIN!

  • Verified answer
    NiloferA Profile Picture
    NiloferA on at
    Re: Error using FORMAT in CREAT CSV TABLE

    Thanks for posting the JSON here @dBrand !

    I got the Flow working with your JSON and JSON Schema with minor changes.

    1. At the beginning of the Flow please initialize a String Variable
    2. In Apply to Each, after Formatted Number, add Set a Variable action and configure it as follows
      1. NiloferA_0-1620101912949.png
      2. In double quotes, select the output from Formatted Number
    3. In Compose Total Pay action, add this expression - replace(string(item()),string(item()?['PayTotalSum']), variables('MyString'))
      1. NiloferA_1-1620102128149.png
    4. Keep the Append to Array Variable as is from the previous replies, the expression should be - json(outputs('Compose_Total_Pay'))
    5. At the end, after the Apply to Each, you already have Create CSV Table action in your Flow, pass the Array in the Input here.

    And that's it. I am certain this should work for you now! Fingers crossed! 😛

    Please give a Kudo or Mark my respective Replies as Solution once this works for you.

  • David Brandman Profile Picture
    David Brandman 294 on at
    Re: Error using FORMAT in CREAT CSV TABLE

    [
    {
    "CleaningHrsSum": 2,
    "CleaningRate": 125,
    "ContainerSum": 5,
    "HolidayHoursSum": 0,
    "HolidayPay": 0,
    "HolidayRate": 0,
    "HoursSum": 0,
    "Non_PowderRate": 100,
    "OTHoursSum": 0,
    "OTPay": 0,
    "OTRate": 0,
    "PayTotalSum": 875,
    "PowderContainerSum": 1,
    "PowderRate": 125,
    "RegPay": 0,
    "RegRate": 0,
    "Worker": 19,
    "WorkerGrpBy": [
    {
    "AddlHours": 0,
    "Cleaning_Hours": 2,
    "Containers": 5,
    "HolidayHours": 0,
    "Hours": 8,
    "PayAmount": 875,
    "Pkey": 292,
    "PowderContainers": 1,
    "RateCleaning": 125,
    "RateHoliday": 0,
    "RateNonPowder": 100,
    "RateOT": 0,
    "RatePowder": 125,
    "RateReg": 0,
    "RecType": "L",
    "Related_Pkey": 281,
    "Status": "S",
    "Submitted": true,
    "cDate": 20210402
    }
    ],
    "WorkerName": "Pat , Barney"
    },
    {
    "CleaningHrsSum": 0,
    "CleaningRate": 125,
    "ContainerSum": 5,
    "HolidayHoursSum": 0,
    "HolidayPay": 0,
    "HolidayRate": 0,
    "HoursSum": 0,
    "Non_PowderRate": 100,
    "OTHoursSum": 0,
    "OTPay": 0,
    "OTRate": 0,
    "PayTotalSum": 625,
    "PowderContainerSum": 1,
    "PowderRate": 125,
    "RegPay": 0,
    "RegRate": 0,
    "Worker": 23,
    "WorkerGrpBy": [
    {
    "AddlHours": 0,
    "Cleaning_Hours": 0,
    "Containers": 5,
    "HolidayHours": 0,
    "Hours": 8,
    "PayAmount": 625,
    "Pkey": 293,
    "PowderContainers": 1,
    "RateCleaning": 125,
    "RateHoliday": 0,
    "RateNonPowder": 100,
    "RateOT": 0,
    "RatePowder": 125,
    "RateReg": 0,
    "RecType": "L",
    "Related_Pkey": 281,
    "Status": "S",
    "Submitted": true,
    "cDate": 20210402
    }
    ],
    "WorkerName": "Dey, Sam"
    },
    {
    "CleaningHrsSum": 0,
    "CleaningRate": 0,
    "ContainerSum": 0,
    "HolidayHoursSum": 8,
    "HolidayPay": 200,
    "HolidayRate": 25,
    "HoursSum": 0,
    "Non_PowderRate": 0,
    "OTHoursSum": 0,
    "OTPay": 0,
    "OTRate": 24.75,
    "PayTotalSum": 200,
    "PowderContainerSum": 0,
    "PowderRate": 0,
    "RegPay": 0,
    "RegRate": 16.5,
    "Worker": 15,
    "WorkerGrpBy": [
    {
    "AddlHours": 0,
    "Cleaning_Hours": 0,
    "Containers": 0,
    "HolidayHours": 8,
    "Hours": 0,
    "PayAmount": 200,
    "Pkey": 307,
    "PowderContainers": 0,
    "RateCleaning": 0,
    "RateHoliday": 25,
    "RateNonPowder": 0,
    "RateOT": 24.75,
    "RatePowder": 0,
    "RateReg": 16.5,
    "RecType": "M",
    "Related_Pkey": 284,
    "Status": "S",
    "Submitted": true,
    "cDate": 20210402
    }
    ],
    "WorkerName": "Etlan , Cam"
    },
    {
    "CleaningHrsSum": 0,
    "CleaningRate": 0,
    "ContainerSum": 0,
    "HolidayHoursSum": 0,
    "HolidayPay": 0,
    "HolidayRate": 0,
    "HoursSum": 8,
    "Non_PowderRate": 0,
    "OTHoursSum": 0,
    "OTPay": 0,
    "OTRate": 33,
    "PayTotalSum": 176,
    "PowderContainerSum": 0,
    "PowderRate": 0,
    "RegPay": 176,
    "RegRate": 22,
    "Worker": 36,
    "WorkerGrpBy": [
    {
    "AddlHours": 0,
    "Cleaning_Hours": 0,
    "Containers": 0,
    "HolidayHours": 0,
    "Hours": 8,
    "PayAmount": 176,
    "Pkey": 315,
    "PowderContainers": 0,
    "RateCleaning": 0,
    "RateHoliday": 0,
    "RateNonPowder": 0,
    "RateOT": 33,
    "RatePowder": 0,
    "RateReg": 22,
    "RecType": "D",
    "Related_Pkey": 314,
    "Status": "S",
    "Submitted": true,
    "cDate": 20210402
    }
    ],
    "WorkerName": "Ady, John"
    },
    {
    "CleaningHrsSum": 2,
    "ContainerSum": 10,
    "HolidayHoursSum": 8,
    "HolidayPay": 200,
    "HoursSum": 8,
    "OTHoursSum": 0,
    "OTPay": 0,
    "PayTotalSum": 1876,
    "PowderContainerSum": 2,
    "RegPay": 176,
    "Worker": 0,
    "WorkerName": "TOTAL:"
    }
    ]

  • NiloferA Profile Picture
    NiloferA on at
    Re: Error using FORMAT in CREAT CSV TABLE

    I agree that might be the reason, can you paste the actual JSON here please?

    I will add it in my flow and troubleshoot.

  • David Brandman Profile Picture
    David Brandman 294 on at
    Re: Error using FORMAT in CREAT CSV TABLE

    I had also tried that, thinking that's what you meant. But it gives a different error:

     

    InvalidTemplate. Unable to process template language expressions in action 'Append_to_array_variable' inputs at line '1' and column '2894': 'The template language function 'json' parameter is not valid. The provided value '{"CleaningHrsSum":2,"CleaningRate":125,"ContainerSum":5,"HolidayHoursSum":0,"HolidayPay":0,"HolidayRate":0,"HoursSum":0,"Non_PowderRate":100,"OTHoursSum":0,"OTPay":0,"OTRate":0,"PayTotalSum":$875.00,"PowderContainerSum":1,"PowderRate":125,"RegPay":0,"RegRate":0,"Worker":19,"WorkerGrpBy":[{"AddlHours":0,"Cleaning_Hours":2,"Containers":5,"HolidayHours":0,"Hours":8,"PayAmount":$875.00,"Pkey":292,"PowderContainers":1,"RateCleaning":125,"RateHoliday":0,"RateNonPowder":100,"RateOT":0,"RatePowder":125,"RateReg":0,"RecType":"L","Related_Pkey":281,"Status":"S","Submitted":true,"cDate":20210402}],"WorkerName":"Pam , Raff"}' cannot be parsed: 'Unexpected character encountered while parsing value: $. Path 'PayTotalSum', line 1, position 191.'. Please see https://aka.ms/logicexpressions#json for usage details.'.

     

     

    Not sure if this is due to my Schema and maybe the way we write this needs to be diffferent because of that?

     

    Schema:

    {
      "type""array",
      "items": {
        "type""object",
        "properties": {
          "CleaningHrsSum": {
            "type""number"
          },
          "CleaningRate": {
            "type""number"
          },
          "ContainerSum": {
            "type""number"
          },
          "HolidayHoursSum": {
            "type""number"
          },
          "HolidayPay": {
            "type""number"
          },
          "HolidayRate": {
            "type""number"
          },
          "HoursSum": {
            "type""number"
          },
          "Non_PowderRate": {
            "type""number"
          },
          "OTHoursSum": {
            "type""number"
          },
          "OTPay": {
            "type""number"
          },
          "OTRate": {
            "type""number"
          },
          "PayTotalSum": {
            "type""number"
          },
          "PowderContainerSum": {
            "type""number"
          },
          "PowderRate": {
            "type""number"
          },
          "RegPay": {
            "type""number"
          },
          "RegRate": {
            "type""number"
          },
          "Worker": {
            "type""integer"
          },
          "WorkerGrpBy": {
            "type""array",
            "items": {
              "type""object",
              "properties": {
                "AddlHours": {
                  "type""number"
                },
                "Cleaning_Hours": {
                  "type""number"
                },
                "Containers": {
                  "type""number"
                },
                "HolidayHours": {
                  "type""number"
                },
                "Hours": {
                  "type""number"
                },
                "PayAmount": {
                  "type""number"
                },
                "Pkey": {
                  "type""integer"
                },
                "PowderContainers": {
                  "type""number"
                },
                "RateCleaning": {
                  "type""number"
                },
                "RateHoliday": {
                  "type""number"
                },
                "RateNonPowder": {
                  "type""number"
                },
                "RateOT": {
                  "type""number"
                },
                "RatePowder": {
                  "type""number"
                },
                "RateReg": {
                  "type""number"
                },
                "RecType": {
                  "type""string"
                },
                "Submitted": {
                  "type""boolean"
                },
                "cDate": {
                  "type""integer"
                }
              },
              "required": [
                "AddlHours",
                "Cleaning_Hours",
                "Containers",
                "HolidayHours",
                "Hours",
                "PayAmount",
                "Pkey",
                "PowderContainers",
                "RateCleaning",
                "RateHoliday",
                "RateNonPowder",
                "RateOT",
                "RatePowder",
                "RateReg",
                "RecType",
                "Submitted",
                "cDate"
              ]
            }
          },
          "WorkerName": {
            "type""string"
          }
        },
        "required": [
          "CleaningHrsSum",
          "ContainerSum",
          "HolidayHoursSum",
          "HolidayPay",
          "HoursSum",
          "OTHoursSum",
          "OTPay",
          "PayTotalSum",
          "PowderContainerSum",
          "RegPay",
          "Worker",
          "WorkerName"
        ]
      }
    }
  • NiloferA Profile Picture
    NiloferA on at
    Re: Error using FORMAT in CREAT CSV TABLE

    Dont worry about it, it's fine.

    Although, I just noticed that in the screenshot you provided above, the expression in Append to Array Variable action is - json(outputs(Output)) which is incorrect. 

    Please remove the value, then when the Dynamic Content popup comes up, click on Expression and then type in json() and within this function add the Output of Compose Total Pay from Dynamic Content.

    So the expressions should look like this -->   json(outputs('Compose_Total_Pay')) 

    Please refer the Screenshots below

    NiloferA_0-1620069238746.png

    NiloferA_1-1620069292474.png

    NiloferA_2-1620069333281.png

     

     

  • David Brandman Profile Picture
    David Brandman 294 on at
    Re: Error using FORMAT in CREAT CSV TABLE

    Sorry, I now feel like a nuisance, but now getting error:

     

    Unable to process template language expressions in action 'Append_to_array_variable' inputs at line '1' and column '2894': 'The template language function 'json' expects its parameter to be a string or an XML. The provided value is of type 'Array'. Please see https://aka.ms/logicexpressions#json for usage details.'.

     

    To be certain, you wanted it to be 'Compose' and not 'Compose Total Pay'? Either way didn't work though. But the other way gave a different error.

  • NiloferA Profile Picture
    NiloferA on at
    Re: Error using FORMAT in CREAT CSV TABLE

    Ok, I got your issue.

    In Append to array variable, Please add the value as an expression and not as text in the field.

    NiloferA_0-1620051628788.png

     

  • David Brandman Profile Picture
    David Brandman 294 on at
    Re: Error using FORMAT in CREAT CSV TABLE

    From what I see, I am passing an Array, which is why I am confused. But below are screenshots to help better see my flow, as requested. Thanks!!!

     

    dBrand_0-1620048682727.png

     

     

    The Apply to each breakout:

    dBrand_1-1620048714310.png

     

  • NiloferA Profile Picture
    NiloferA on at
    Re: Error using FORMAT in CREAT CSV TABLE

    Hello @dBrand ,

    It looks like you are passing string and not array to the CSV table action. Can you please confirm the type of the variable you have initialized?

    NiloferA_1-1620012507787.png

    NiloferA_6-1620012808188.png

     

    NiloferA_2-1620012600262.png

    NiloferA_3-1620012623689.png

    NiloferA_5-1620012725427.png

     

    Also, if possible please post screenshots of your flow here for me to assess the problem better! 🙂

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard