cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thuff
Helper I
Helper I

When Building an array......

I am building an array (i think) to be parsed later and i'm questioning the structure that I've used, specifically, how i'm separating 'entry1' from 'entry2'

 

This is the format i'm looking to achieve in the "ROLLINGUPDATE" field

[{"Date":"SOMEDATE"},{"Time":"SOMETIME"},{"By":"SomePerson"},{"Update":"UPDATES go here"}]

[{"Date":"SOMEDATE"},{"Time":"SOMETIME"},{"By":"SomePerson"},{"Update":"UPDATES go here"}]

[{"Date":"SOMEDATE"},{"Time":"SOMETIME"},{"By":"SomePerson"},{"Update":"UPDATES go here"}]

 

So i currently have

image.png

 

and if conditions match, i would append to that variable with the contents of the rolling update field

image.png

 

 

Which currently gives me

[{"Date":"10-Mar-2020"},{"Time":"03:32:57"},{"By":"TestPerson"},{"Update":"First Update"}],
[{"Date":"10-Mar-2020"},{"Time":"03:32:49"},{"By":"TestPerson"},{"Update":"First Update"}],
[{"Date":"10-Mar-2020"},{"Time":"03:32:39"},{"By":"TestPerson"},{"Update":"First Update"}],
[{"Date":"10-Mar-2020"},{"Time":"03:28:30"},{"By":"TestPerson"},{"Update":"First Update"}],
[{"Date":"10-Mar-2020"},{"Time":"03:28:23"},{"By":"TestPerson"},{"Update":"First Update"}],
[{"Date":"10-Mar-2020"},{"Time":"03:28:17"},{"By":"TestPerson"},{"Update":"First Update"}],

 

 

 

Is my format correct? Specifically i'm wondering about the comma at the end of each line - i'm just not sure if that is appropriate

 

 

FYI, if it helps, this is my parsing format

 

{
    "type": "array",
    "items": {
"type": "object",
        "properties": {
            "Date": {
                "type": "string"
            },
            "Time": {
                "type": "string"
            },
            "By": {
                "type": "string"
            },
            "Update": {
                "type": "string"
            }
        },
        "required": []
    }
}
 
Thanks!

 

7 REPLIES 7
efialttes
Super User
Super User

Hi

What I would expect inside an array is a number of similar elements. In your case you are adding objects (that's fine) but each of them have different properties.

 

Also if you want to create an array via 'Initialize variable' my suggestion is to select as its type 'Array' instead of 'String'.

Please also note there is an action block called 'Append to array variable' that should be used if you declare your variable as array.

 

An array cannot end with a comma.

Commas shall separate the different elements of an array.

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



abm
Super User
Super User

Hi @thuff 

 

Yes that comma will be an issue. So to overcome you could initialise an integer count and check if counter > 1 then  in your Append string use expression concat with comma and rollingupdate else just use the rollingupdate. Also make sure in your initialise WeeklyUpdateString do not use any comma at the end.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Thank you @abm and @efialttes ,

 

Clearly I was confused on the structures. I have long had a basic misunderstanding between arrays & objects - i think i recall the key difference being that (by and large) arrays assume order and objects do not. For these purposes, i think ( and i'm willing to be wrong!) that restating the variables as arrays is the logical approach and start by redefining the structure of that first variable  as object. e.g. 

 

 

{"Date":"@{formatDateTime(utcNow(),'dd-MMM-yyyy')}","Time":"@{formatDateTime(utcNow(),'HH:mm:ss')}","By":"TestPerson","Update":"@{triggerBody()?['Status_x0020_Update']}"}

 

 

 

I will play with this and let you know - thank you both (and please let me know if that sounds crazy!) 

Hi again

Your new approach sounds more common nowadays.

Since you get confused sometimes with arrays and objects, I would recommentd the following link for better understanding of arrays...

https://sharepains.com/2018/07/10/microsoft-flow-shed-some-light-on-arrays/

...and this other link for better understanding of objects in JSON format

https://sergeluca.wordpress.com/2017/11/23/using-json-in-microsoft-flow-part-1/

Please note this second link has a typo, when Serge says:

  • Add a compose action of type Object.
  • Name the variable ‘Pilots’.
  • Paste the following JSON object...

...what he really wants to say is:

  • Add a Initialize Variable of type Object.
  • Name the variable ‘Pilots’.
  • Paste as its Value the following JSON object...

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



hi @efialttes ,

 

That is supremely helpful and both make a lot of sense. entertaining reads. After i read those i thought 'oh i just need to join objects' but now after reading the articles again, i think i need to parse objects , grab the body as an array, append to array.

 

Or perhaps there is such thing as just append to object? 

Hi
Many common action blocks (sharepoint gat items, lanner get tasks, excel get rows...) provide an putput in json format (object), but one of ita main properties is an array with object elements inside. In such context, each object element is a representation of one SP item, one Planner task, one Excel row. And the SP list column values for such item, the Planner task properties for that task, the Excel column values for that row are represented as properties of the object
Hope this helps


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hi!
Is this issue solved? If so, please remember to mark the key reply as a solution, so it will help others in the future
Thanx!


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,832)