Power Apps Dynamic Text Strings | Documents | Prompts | Paragraphs #PowerApps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
by folks in today's demonstration I'm going to show you how I built a power app to dynamically populate strings within a paragraph of text so these paragraphs have placeholders I'm using pipe delimited characters in order to indicate where those parameters are due to go and I'm going to show you both an example but also how to build it from scratch so that you can dynamically populate your own properties into paragraphs or text using a power app this is perfect for populating Word documents but also may be very useful for generating prompts for your GPT models so as always I'll encourage you to like And subscribe and without further Ado let's jump into the demonstration so I'm going to kick things off from my canvas app and I'm going to show you a very basic example that I've built and then afterwards I'll show you how to actually build this with a more complex example using a SharePoint list as a data source and several paragraphs so what you're seeing on screen right now is a screen that contains a paragraph of text we have a couple couple of input parameters based on the cost and the dimensions and you'll notice that both of those are encapsulated in pipes and that's what helps us to identify those parameters dynamically beneath that I have a gallery and in that Gallery we have a couple of text input controls those are also generated dynamically based on anything that is pipe encapsulated so if we want to have multiple parameters we want to enable folk to be able to provide some data to then populate that paragraph at text we can do that dynamically and one thing that Springs to mind as well as being able to use this to generate Word documents for instance or paragraphs of text it might actually be quite useful for building out prompts so if you're using prompts as a concept for chat GPT you might want to parameterize those prompts and by using this technique you can actually make the input properties for that prompt totally Dynamic using the method that I'm now demonstrating on screen so what happens now if I go to play I I have the ability to insert a cost and we'll go with a price of $19.99 and we can have some Dimensions so 10 by 20 by 40 and if I hit the populate button what you'll see below is that paragraph of text populated now with those input parameters and you'll note that the price is actually referenced twice and the reason I mentioned that is later on you'll see some important code that I've inserted so that we only get the ability to provide the cost once despite it being referenced twice in the paragraph of text above now if we want to extend this and add in a new parameter I can pop open the text here and we can maybe insert the product name I'll type in called and then product name but I'll encapsulate product name in pipes so we'll just go and wrap product name in pipes and if I just collapse that and look back at our app you can now see I have a new input control for the product name so so like I mentioned at the beginning this is completely Dynamic based on the number of properties that you have encapsulated in the double pipes this Gallery will update to then provide you some input controls for those values so if I play the app once more and give our product a name and we can go with the GPT headset 2000 the cost is going to be 2,000 and in fact I'll put a pound sign at the beginning there and the dimensions are going to be 20 by 50 by 200 massive and we'll hit populate and you'll see here we have as expected a new paragraph of text called the GPT headset 2000 with the price at £2,000 both here in the middle of the text but also at the bottom and then our dimensions in the placeholder there for Dimensions so how do we build this so back into edit the first thing to call out really is the data source for the items of our Gallery so you can see I have Gallery here it has two controls one is a text input and one is a label so the label is based on the tag the text input of course is based on the text that we need to supply for that label but the items is based on a regular expression and so this regular expression is looking for anything that is pipe encapsulated and by using that regular expression we can obviously then identify all those parameters within that paragraph now in order to explain how this works the first thing I'm going to do is to highlight this match all expression and you'll see that the output is a table and if I pop that open we again we can see those properties or parameters so product name cost dimensions and cost and we can see already that cost appears twice and that's because in the original paragraph of text that property appears twice so hence why I have the expression distinct wrapped round this whole expression and based the distinct is based on the full match Colum column so it will now return me a table of values that are distinct and we can see already that cost has been removed so that's what enables me to create this Dynamic gallery that has just those three properties despite cost appearing twice in the paragraph of text above and of course you can change this to reflect your situation you might want to have cost appearing more than once equally you might just want it to appear once but to populate twice throughout that paragraph that we have so with that in place we have our Gallery we have our distinct values which is based on the properties it's completely Dynamic we saw that when we added product name it added that in if we now go and have a look at the label tag we have an expression which is substitute based on the value and we're looking to substitute all the pipes with nothing and that's purely just to tidy things up and it'll make things a lot easier in the next part of the process in the text input I have a very basic text input no changes we're simply looking to get the values from the end user to enable us to populate that string and it's at this point that I was thinking about how else this could be used not only is it useful for populating paragraphs of text in Word documents for instance if you're building out a GPT model and you have a prompt and you're looking to parameterize that prompt if you use the following technique that I'm demonstrating on screen you could actually parameterize all your prompts and of course grab all those input prop properties dynamically using this Gallery method that I'm demonstrating anyway back onto the demonstration we can see that we have a paragraph of text and it's just a concatenation of a collection the real magic is all happening in this populate button so if I pop open the expression editor we can see the series Expressions I have the first of which is purely setting a variable to the original text control that contains the paragraph of text and I've broken it down like this to hopefully explain how it all works potentially you can Nest a lot of this but the first expression as we see if I double click on it contains that original paragraph of text that has the input parameters encapsulated in those pipes in the second expression I'm updating another variable or setting a varable based on a split and that is splitting out our text string based on the pipes the double pipes and what that will give us is a table of text so if I pop that open now we can see we have the value column here and things like product name and cost will jump out at us right now and then the other stuff the other uh sentences Etc are in separate lines or separate values in the table and what we're going to do in the next part of this uh expression is to Loop through all of these different rows in this table and look for any of the values that match the properties that we have so cost and dimensions are to me and you very obvious that those are properties if they match we can go and replace them with the text that we provided in the text input if they don't match we'll simply keep the original text and that is what happens in the next part of our expression here so I have a very basic expression just to quickly clear my collection of strings and then I have a for all and that for all is going through that whole table of text that we just saw on the screen there you'll notice that I've called out the individual values as text strings just to make it easy for me to identify and then I'm collecting each of the results into a new collection using what's called coales and a lookup and a default value so let's try and have a look at this bit here and understand what's going on so We're looping through of course all the different values that are in the table and what KES does is it Returns the first non-null value and we have two expressions within that coales we have a lookup and we're looking up all of those items in our gallery to see if the text matches the text in our table so if the text equals for instance cost then we know we've got a match and we can return the text Gallery substitute text so if we look at the gallery on the left hand side here in the tree view you can see I have that control called text Gallery substitute so if we get a match in the lookup in the items where the text is equal to the the value that's in that table of strings then we return the substitute text which we've provided in those input controls if we don't get a match then we just return the original text which is the text string. value now this is where KS comes into play KS will return the first non-null value so if we do a lookup we don't get a match we don't get a text string it returns null therefore we keep the original text and so what happens is if we just go and have a look again at that table we pop it open R for all is going through all these different values is there anything in our gallery that matches introducing our incredible new etc etc no there isn't therefore keep the Tex string value is there anything for product name yes there is we do a lookup we get a match we therefore get the text and we can return that and replace the product name with the value that's contained within that uh text gallery substitute control and we work through them one by one in that Loop looking at Cost looking at dimensions and then of course skipping any that are strings that we don't have a match and then ultimately when we get down to our text input control with the text remember we had that concatenation which will just bring back together all of these values now if I just go and double click on the collection string we can see that collection string is exactly the same format it has all of those vales values in a table but where we previously had those parameters because we've had those matches we've used those lookups the coales we now have those text strings replace GPT headset 2000 the 2,000 and the dimensions and if we were to jump back here onto the text control we can see that all we've done is concatenate that original table which we can see here based on the column called result and that just purely brings back together all of those text strings that have been broken down down into a table by using split based on those pipe delimiters and then we've rejoined them back together again once we've substituted it out those values so let's now see if we can build this ourselves from scratch and to make things interesting what I have is a Microsoft list with three different paragraphs and you can see those paragraphs have parameters based on date buyer's name Etc we're going to bring this into our power app we're going to generate some Dynamic input parameters and populate them and see how we can build that from scratch so the first thing I'm going to do is just add in a brand new screen we've got that there and then I've already connected up my data source my paragraphs with parameters that we just saw and what I'd like to do is to insert a new text control or have a text label and we can bring in those paragraphs so the data source for those paragraphs are paragraphs with parameters so paragraphs with parameters they're there are several of them so we will concatenate them using concat and the concatenation is based on the paragraph text column that we have and what I'd like to do is also put in a couple of return lines I'll just show you what happens if I just close that off it'll bring in all my paragraphs like so which looks a bit messy on screen but what I'd like to do is just to insert a couple of return lines so it appears nicely on screen like so so we have our paragraphs of text on screen remember this could be a prompt Etc that you're using we can quite clearly see all those parameters and at the moment we've got no way of doing anything with that text but we're going to build out the same as we saw previously so I need to insert a gallery because of course we need the gallery to display those input values we'll go with a vertical Gallery I'll just move it to the side here and so if I go and just simplify it make it blank so no controls and then we need to sort our our data source so the data source is based on that expression remember it's based on Match all initially so we can type in match all it's based on the content of this text here so if I go and have a look at my tree view I've got label five so if I type in label 5. text that will get me all the text and then I need to insert my regular Expressions so in quotes like so and don't ask me exactly how these regular expressions work cuz I have to admit good old chat gbt helped me on this one but we'll put in as expected this will actually search for any strings within those pipes you might want to specify that the strings only contain uh letters for instance um in order to keep them unique but let's just go with what I've generated and here we go the last bit of pipes here and close it off and if I just go ahead and highlight that we can see that already we're generating a table of data based on those properties in those three paragraphs now remember I want these to be distinct so I'm going to wrap this whole expression here in the word distinct we'll go with that opening and close brackets but it also needs to include the name of the column what are we looking to get distinct values from so full match and now we have those distinct values and if we jump back onto our gallery go into edit I want to insert two controls first first a text label and then a text input if we line them up nicely and maybe resize this as well in fact let's shift this all up and try and get as much on here as possible there we go now you'll note that these uh Properties or parameters have come through with the pipes and before what I used was the replace or substitute in fact I think it was so go with substitute and we're looking to substitute all instances of pipes with nothing and this is where jumping between power apps and power automate often Catch catches me out so it's a double quotes So we need here there we go so that's now working we have our text input if you're really fussy you can remove the default values so we've not got any text in the text input like so so I'll just do a bit of tidying up and rename some of these things so this is the label with the paragraphs of t text this is our gallery of um properties of which we have a text for our property values and we've got our label for our properties and with that all nicely updated if we go and insert a button we can then go and replace all of those properties within our par graphs that we have on screen so the first thing that I did was we'll call this button replace value um was to create a variable and the variable is to store the paragraph of text so I'm to call this Global par text and in there I'll insert the value from our label of paragraph text so label paragraphs of text. text now last time around I actually then run a second query or a second expression to split that but I'll do that all within the one action um and we will also include split on that and we will split on the double pipes so that will now give us our table based on all of those individual strings and let's run that and just see what happens so I'll just hold my ALT press the button and if we have a look at the content now we should be able to see how it is split and because we have variables right at the beginning on such and such a date I such and such buyer's name I'm thrilled to officially start at blah blah blah property address so we can see all these properties coming through it's obvious to us and of course we're going to populate these based on the text that are supplied Within These text inputs with that now in place I can put a semicolon and we'll just open up this expression bar here and we can then look at replacing them next we want to create a collection and I'm going to use clear collect and that collection is going to be used to store our new strings so I'll call it call of strings I've already got call strings I'll call it call strings and I'm going to set that to blank and there we go we can put a semicolon at the end now it's all about looping so we want to go through every single string and see have we got a match in our Gallery if we do get the get the value if we don't use the existing string so for all of our Global paratext which is our table of the split strings and I'm going to call this as text strings so it's easy to refer to in our Expressions what I want to do now is I want to do a collect I can see the autocomplete is getting in the way here so I want to do a collect and that collect is going to be in that new collection that I've just created which is called Co strings and what we want to collect is a nice little object again the autocomplete is getting in the way so I'll delete that put in an opening squiggly bracket and I want to get the value and that particular value is going to be based on a coales so a coales like I mentioned earlier is going to return the first non-null value so the first thing we're going to do is we're going to do a lookup and that lookup is going to be based on the gallery that we've got we're going to have a look at the gallery which I've called Gallery properties we're going to look at all items and we're going to see if the L label of the properties. text is equal to the text string so remember I've renamed or referenced each of the values in our Global par text as text strings. value exist and if it does exist we want to get back the text property values. text so if there's a match and we look up that gallery of properties if there's a match on the string we get back the text property value which is our text input and then we swap that out if it doesn't exist then we have the fallback property which is the text string dot value and we can put the closing bracket there and we can finish that off with a curly bracket which gives us our object or our record and then finally I can close it off with two closing brackets and we have our completed expression so if I format that text we can see what it looks like we initially we set our Global variable we're splitting on those pipes which gives us our table of all those strings we create a blank collection and then for all of the strings in that table of text we're basically looking up our gallery to see if the string matches the string in our original table of text if it does we can return the appropriate value from the text input property values if it doesn't we fall back onto the original text string value by using coales which will return the first non null value so if we close that and give that a go I am going to have to go and Supply some dates Etc so I'm going to put in today's date the 17th of February 2024 the buyer's name I can save as myself property address was a house in Scotland agent's name is uh Jack Smith purchase price we'll go for 200,000 payment method we'll say cash closing date is in fact the 18th so it's tomorrow and um we can continue through the last few properties so the seller's name can be Jim McDonald um party responsible no idea what that is but we'll put in me and the deposit amount we can say was 20 20,000 and if I hit the button whilst we won't see the text upd what we can have a look at is if we go and click on that button and open up our expression bar again I can go and pop open the collection and have a look at that table and we can see now the date 17th the 2nd my name Etc has been placed into these placeholders that I have and these individual values within this table and if I want to turn that into a brand new string I just need to do a concatenation so for the sake of any argument what I'm going to do is I'm going to create a new screen I'm going to insert a text label can make that full screen here and all we need to do is insert that conat instruction we'll use our collection of strings this time and we will join on the value and that should give us our populated text there we can see on the 17th of February 24 Damian I am thrilled to start the Journey of purchasing my new home at a house in Scotland Etc and we can see where it's populated my name again and Jim McDonald and and inserted all of the other Dynamic values now of course if you're looking to get this into a Word document I do have an example of dynamic documents using a Microsoft form and I actually do the population of all the strings using power automates but in this particular scenario I'm populating all those Dynamic properties within power apps so you could now send this directly to populate a Word document you could pass this whole string to power automate and save it within a data source somewhere or save it within a Word document or into email for instance and like I mentioned earlier on this would work extremely well if you're using prompts for GPT so hopefully I've given you some inspiration some ideas shown you some techniques with some of those expressions and power apps I'd love to hear in the comments below how you've use this yourself what you've learned and if you haven't already please make sure you like And subscribe and I look forward to seeing you again sometime soon thanks for watching cheers bye
Info
Channel: DamoBird365
Views: 1,519
Rating: undefined out of 5
Keywords: powerapps tutorial, dynamic strings, power apps populate dynamic text, dynamic text template power apps, dynamic form in powerapps, dynamic text template powerapp, text input control in powerapps, dynamic template powerapp, dynamic content powerapp, power app create document, power app create word document, power app template document, powerapps substitute, power apps substitute multiple words, powerapps substitute multiple characters, powerapps substitute multiple
Id: Zex-jooO5io
Channel Id: undefined
Length: 24min 14sec (1454 seconds)
Published: Sat Feb 17 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.