cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dBrand
Helper III
Helper III

Error using FORMAT in CREAT CSV TABLE

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

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

17 REPLIES 17
dBrand
Helper III
Helper III

Reallyhoping someone has some ideas on this. Still stuck. Thanks!

Hello @dBrand !

 

I notice that you have added your action of Create CSV Table outside of the Apply to Each action and still trying to refer the "Current item" which is coming from Apply to Each.

Try moving Create CSV Table action within Apply to Each after the Format action and it should work for you.

 

Hope this helps! Please give a Kudo and mark this Reply as solution if you found it helpful.

I tried this, but now get the error:

BadRequest. The 'from' property value in the 'table' action inputs is of type 'Object'. The value must be of type 'Array'.

 

Here is the flow:

dBrand_0-1619888538505.png

 

Additionally, I am trying to get the columns in the CSV to be from the original parsed Json as well as some fields from the Format steps (since they will provide a formatted dollar amount, where the Parsed data does not).

 

Still stuck on this for days, and can't really find an answer to this, and my deadline is Monday.

Hello @dBrand ,

I got your problem statement working. Please make below changes to your flow to achieve the requirement,

  1. Initialize an Array (MyArray) Variable
  2. Then in Apply to Each action, after Format Number, add a Compose action and add the expression in input as follows
    1. replace(string(item()), item()['ro'] (name of the field you are trying to replace with formatted number)(Output from Format Number Dynamic Content))
  3. Then add Append to Array Variable action and add the following expression in Value
    1. json(outputs('Compose'))
      NiloferA_0-1619975928309.png
  4. Outside of the Apply to Each action, add the Create CSV Table action and pass the Array to it.

NiloferA_1-1619975973709.png

This should solve your issues. Now the problem with your Flow is that

  1. You are traversing JSON Body and passing each item (which is of type Object) to Create a CSV Table action, this action accepts an Array not an Object
  2. You are formatting some field from the JSON but you are never updating the current item thus your updated format will not appear in the final result.

Hope this helps you out and you should be good for your deadline! If you still face any issues, feel free to post a reply and I will be happy to help!

Please give a Kudo and mark this Reply as solution if you found it helpful.

 

Thanks, sorry, but I'm stuck. In step 2a - 

  1. replace(string(item()), item()['ro'] (name of the field you are trying to replace with formatted number) (Output from Format Number Dynamic Content))

I replace it with my data, below, but I am getting an invalid expression. Not sure of the syntax.

replace(string(item()), item()['PayTotalSum'], (outputs('Format_number_Total_Pay')?['body']))

 

But, I do understand the concept of the solution you provided, which seems to be the answer, if I could just get past the syntax issue I am having.

 

Thanks!

No problem @dBrand , so your expression should look like this

replace(string(item()),item()?['PayTotalSum'], outputs('Format_number_Total_Pay')?['body'])
Get rid of the brackets near Format Number Output.

Just about there. Now getting past that and getting error creating the CSV table, which I am doing from the array (or so I believe):

dBrand_0-1620001680829.png

 

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! 🙂

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

 

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

 

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.

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

 

 

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"
    ]
  }
}

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

I will add it in my flow and troubleshoot.

[
{
"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:"
}
]

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.

View solution in original post

@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!

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!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,418)