{"id":2390,"date":"2025-04-03T18:31:58","date_gmt":"2025-04-03T16:31:58","guid":{"rendered":"https:\/\/blog.kodono.info\/wordpress\/?p=2390"},"modified":"2025-04-03T18:32:11","modified_gmt":"2025-04-03T16:32:11","slug":"power-fx-dynamically-access-an-object-propery-with-a-variable","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2025\/04\/03\/power-fx-dynamically-access-an-object-propery-with-a-variable\/","title":{"rendered":"Power FX: Dynamically access an object property with a variable"},"content":{"rendered":"<p>I&#8217;m kind of new with Power Apps, and it&#8217;s been very difficult to find how to access an object property using a variable.<\/p>\n<p>In a nutshell, here are to access it:<\/p>\n<pre class=\"brush:R\">\r\nWith(\r\n  { tempData: ParseJSON(JSON(ThisItem, JSONFormat.IgnoreBinaryData &#038; JSONFormat.IgnoreUnsupportedTypes)) },\r\n  Concat(\r\n    ForAll(\r\n      ColumnArray As ColumnName,\r\n      ColumnName.Value &#038; \"=>\" &#038; Column( tempData, ColumnName.Value ) &#038; \"&lt;br>\"\r\n    ),\r\n    Value\r\n  )\r\n)\r\n<\/pre>\n<p>I&#8217;m transforming my record <code>ThisItem<\/code> to an UntypedObject to make it work with <code>Column()<\/code>, using <b>JSON<\/b> and by removing the problematic properties (thanks to <code>JSONFormat.IgnoreBinaryData &#038; JSONFormat.IgnoreUnsupportedTypes<\/code>).<\/p>\n<p>Then I iterate my array (a.k.a <code>ColumnArray<\/code>) that contains the property I need, and I use <code>Column( tempData, ColumnName.Value )<\/code> to extract the column from the record!<\/p>\n<p><strong>My use case<\/strong>: I defined a collection with a list of columns, then I have a Gallery in which I have an HTMLText component that must display the columns from <code>ThisItem<\/code> based on the collection I defined before.<\/p>\n<p>So, in <code>App<\/code> screen, I defined my collection like that:<\/p>\n<pre class=\"brush:R\">\r\nClearCollect(ColumnArray,[\"ID\", \"Title\", \"Description\", \"Target_x0020_Start_x0020_Date\", \"AssignedTo\"]);\r\nClearCollect(UserColumns, [\"AssignedTo\"]);\r\n<\/pre>\n<p>Then in my Gallery, I have an HTMLText object with the below content:<\/p>\n<pre class=\"brush:R\">\r\n\"&lt;div style='display:grid;grid-template-columns: 100px 50px 1fr 1fr 100px 150px;gap: 0px;height:65px;max-height:65px;overflo:hidden'>&lt;div style='\"&#038;cssTdStyle&#038;\";display:flex;justify-content:center;'>&lt;button type='button'>Edit&lt;\/button>&lt;\/div>\" &#038;\r\nWith(\r\n  { tempData: ParseJSON(JSON(ThisItem, JSONFormat.IgnoreBinaryData &#038; JSONFormat.IgnoreUnsupportedTypes)) },\r\n  Concat(\r\n    ForAll(\r\n      ColumnArray As ColumnName,\r\n      \"&lt;div style='\"&#038;cssTdStyle&#038;\"'>\" &#038;\r\n  If(\r\n    ColumnName.Value in UserColumns,\r\n    Column( tempData, ColumnName.Value ).DisplayName,\r\n    Column( tempData, ColumnName.Value )\r\n  )\r\n  &#038; \"&lt;\/div>\"\r\n    ),\r\n    Value\r\n  )\r\n)\r\n&#038; \"&lt;\/div>\"\r\n<\/pre>\n<p>This way I can make my display dynamic, based on a list of columns (that can be populated using a Power Automate Flow). I&#8217;ll have to identify which columns are User type, or similar ones, in order to access to the next property (like <b>.DisplayName<\/b>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m kind of new with Power Apps, and it&#8217;s been very difficult to find how to access an object property using a variable. In a nutshell, here are to access it: With( { tempData: ParseJSON(JSON(ThisItem, JSONFormat.IgnoreBinaryData &#038; JSONFormat.IgnoreUnsupportedTypes)) }, Concat( ForAll( ColumnArray As ColumnName, ColumnName.Value &#038; &#8220;=>&#8221; &#038; Column( tempData, ColumnName.Value ) &#038; &#8220;&lt;br>&#8221; ), [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[15,23,170,13,33],"tags":[153,156,123,152,158],"class_list":["post-2390","post","type-post","status-publish","format-standard","hentry","category-astuce","category-debug","category-english","category-niveau-intermediaire","category-programmation","tag-astuce","tag-debug","tag-english","tag-niveau-intermediaire","tag-programmation"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=2390"}],"version-history":[{"count":8,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2390\/revisions"}],"predecessor-version":[{"id":2398,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2390\/revisions\/2398"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=2390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=2390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=2390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}