{"id":2170,"date":"2022-11-30T09:43:25","date_gmt":"2022-11-30T08:43:25","guid":{"rendered":"https:\/\/blog.kodono.info\/wordpress\/?p=2170"},"modified":"2022-11-30T16:06:10","modified_gmt":"2022-11-30T15:06:10","slug":"pass-an-url-parameter-to-a-sharepoint-online-forms-field","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2022\/11\/30\/pass-an-url-parameter-to-a-sharepoint-online-forms-field\/","title":{"rendered":"Pass an URL parameter to a SharePoint Online form&#8217;s field"},"content":{"rendered":"<p>The only way to pass a URL parameter to a SharePoint Online (modern design) form&#8217;s field is to use PowerApps (at least, if you cannot add any JS on your website!).<\/p>\n<p><b style=\"color:red\">Important warning<\/b>: when you use PowerApps to manage your form, all edits to the list settings won&#8217;t reflect to the PowerApps form. For example, if you add a field, it won&#8217;t show up, and you&#8217;ll have to manually update the PowerApps to add it (see at the bottom of this article).<\/p>\n<p>From the list view, go to <code>Integrate<\/code> then <code>PowerApps<\/code> and <code>Customize forms<\/code>:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/integrate.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/integrate.png\" alt=\"\" width=\"931\" height=\"161\" class=\"aligncenter size-full wp-image-2172\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/integrate.png 931w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/integrate-300x52.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/integrate-768x133.png 768w\" sizes=\"auto, (max-width: 931px) 100vw, 931px\" \/><\/a><\/p>\n<p>Once PowerApps has open the form, you need to do several things.<\/p>\n<h2>1. Load the ID<\/h2>\n<p>We first need to make sure the form will load the required item when we pass the <code>ID<\/code> URL parameter:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_mode_item.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_mode_item-1024x442.png\" alt=\"\" width=\"1024\" height=\"442\" class=\"aligncenter size-large wp-image-2175\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_mode_item-1024x442.png 1024w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_mode_item-300x130.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_mode_item-768x332.png 768w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_mode_item-1536x663.png 1536w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_mode_item.png 1899w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>From the <b>SharepointForm Advanced Settings<\/b>, we change the <b>DefaultMode<\/b> to check if we have the <code>ID<\/code> parameter, and if we don&#8217;t have it, then it should be a New Form, otherwise an Edit Form:<\/p>\n<pre class=\"brush:powershell\">If(IsBlank(Param(\"ID\")), FormMode.New, FormMode.Edit)<\/pre>\n<p>From the <b>SharepointForm Advanced Settings<\/b>, we change the <b>Item<\/b> section to check if we have the <code>ID<\/code> parameter, and if we have it, then we do a lookup in our list to find the data:<\/p>\n<pre class=\"brush:powershell\">If(IsBlank(Param(\"ID\")), SharePointIntegration.Selected, LookUp('NAME OF THE LIST',\u00a0ID = Value(Param(\"ID\"))))<\/pre>\n<h2>Add a SUBMIT button<\/h2>\n<p>With PowerApps, there is no button to save the changes! We&#8217;ll add a button in the form:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/save_btn.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/save_btn-1024x274.png\" alt=\"\" width=\"1024\" height=\"274\" class=\"aligncenter size-large wp-image-2178\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/save_btn-1024x274.png 1024w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/save_btn-300x80.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/save_btn-768x206.png 768w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/save_btn-1536x411.png 1536w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/save_btn.png 1898w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>In the button&#8217;s properties, we change the <b>onSelect<\/b> to be:<\/p>\n<pre class=\"brush:powershell\">SubmitForm(SharePointForm1)<\/pre>\n<p>Be aware that the page will stay with the form after clicking on the button. You could want to close using the <a href=\"https:\/\/learn.microsoft.com\/en-us\/power-platform\/power-fx\/reference\/function-exit\">Exit()<\/a> function, but the user will be redirected on office.com \u2026 I&#8217;d recommend to use <a href=\"https:\/\/learn.microsoft.com\/en-us\/power-platform\/power-fx\/reference\/function-param\">Launch()<\/a> by redirecting your users to a page:<\/p>\n<pre class=\"brush:powershell\">SubmitForm(SharePointForm1); Launch(\"https:\/\/tenant.sharepoint.com\/sites\/MySite\/\");<\/pre>\n<h2>Set field&#8217;s value based on URL parameter<\/h2>\n<p>We can finally set the field&#8217;s value based on the parameter in the URL. Select the INPUT zone of the field, and in the <b>Default<\/b> section we use the below formula:<\/p>\n<pre class=\"brush:powershell\">If(IsBlank(Param(\"Title\")), ThisItem.Title, Param(\"Title\"))<\/pre>\n<p><a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/title_value.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/title_value-1024x281.png\" alt=\"\" width=\"1024\" height=\"281\" class=\"aligncenter size-large wp-image-2179\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/title_value-1024x281.png 1024w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/title_value-300x82.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/title_value-768x211.png 768w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/title_value-1536x422.png 1536w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/title_value.png 1903w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>Here my field is called &#8220;Title&#8221; so I decided to use a parameter called &#8220;Title&#8221; as well.<\/p>\n<h2>Link to the form<\/h2>\n<p>We cannot use the <b>NewForm.aspx<\/b> or <b>EditForm.aspx<\/b> to access this form, but we need a special link.<\/p>\n<p>Go to your <b>list settings<\/b>:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/list_settings.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/list_settings.png\" alt=\"\" width=\"934\" height=\"363\" class=\"aligncenter size-full wp-image-2180\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/list_settings.png 934w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/list_settings-300x117.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/list_settings-768x298.png 768w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><\/a><\/p>\n<p>Then go to the <b>form settings<\/b> (it&#8217;s from there that you can decide to keep PowerApps or use the original Sharepoint Forms), and click on <b>See versions and usage<\/b>:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_settings.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_settings.png\" alt=\"\" width=\"980\" height=\"274\" class=\"aligncenter size-full wp-image-2181\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_settings.png 980w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_settings-300x84.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/form_settings-768x215.png 768w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/a><\/p>\n<p>You&#8217;ll get the <b>App Id<\/b> from this page:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/app_id.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/app_id.png\" alt=\"\" width=\"273\" height=\"166\" class=\"aligncenter size-full wp-image-2182\" \/><\/a><\/p>\n<p>Next, you&#8217;ll use the <b>App Id<\/b> to forge the URL: <b>https:\/\/apps.powerapps.com\/play\/providers\/Microsoft.PowerApps\/apps\/APP_ID<\/b><br \/>\nWith our example, the URL will be: <a href=\"https:\/\/apps.powerapps.com\/play\/providers\/Microsoft.PowerApps\/apps\/c6f23ac1-dcbd-4daf-925e-2701ab241ca0\">https:\/\/apps.powerapps.com\/play\/providers\/Microsoft.PowerApps\/apps\/c6f23ac1-dcbd-4daf-925e-2701ab241ca0<\/a><\/p>\n<p>You can now pass the URL parameter: <b>https:\/\/apps.powerapps.com\/play\/providers\/Microsoft.PowerApps\/apps\/APP_ID?Title=Hello%20World<\/b><br \/>\nAnd an ID to retrieve an existing item: <b>https:\/\/apps.powerapps.com\/play\/providers\/Microsoft.PowerApps\/apps\/APP_ID?Title=Hello%20World&#038;ID=2<\/b><\/p>\n<h2>How to use it with a LookUp column?<\/h2>\n<p>If you want to auto-select a LookUp field using an URL parameter, you need to do a few things\u2026<\/p>\n<p>First, we need to add the related table. To do so, click on <b>Data<\/b> in the left navigation bar and search for <b>SharePoint<\/b>:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/datasource_sharepoint.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/datasource_sharepoint.png\" alt=\"\" width=\"351\" height=\"512\" class=\"aligncenter size-full wp-image-2188\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/datasource_sharepoint.png 351w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/datasource_sharepoint-206x300.png 206w\" sizes=\"auto, (max-width: 351px) 100vw, 351px\" \/><\/a><\/p>\n<p>Search for the table and add it.<\/p>\n<p>Second (optional) step: click on the Lookup field in the form and change the <b>Items<\/b> to show a list of options \u2013 if no &#8220;Lookup&#8221; ID in the URL, then we use the default list of options:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/items_options.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/items_options-1024x218.png\" alt=\"\" width=\"1024\" height=\"218\" class=\"aligncenter size-large wp-image-2192\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/items_options-1024x218.png 1024w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/items_options-300x64.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/items_options-768x163.png 768w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/items_options-1536x327.png 1536w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/items_options.png 1898w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>The below formula permits to retrieve the &#8220;ID&#8221; and &#8220;Title&#8221; from the distant list, base on the &#8220;Lookup&#8221; parameter, and to rename the result as <code>{Id:\"ID\", Value:\"Title\"}<\/code>:<\/p>\n<pre class=\"brush:powershell\">If(IsBlank(Param(\"Lookup\")), Choices([@'CURRENT LIST NAME'].COLUMN_NAME), RenameColumns(ShowColumns(Filter('DISTANT LIST NAME', ID = Value(Param(\"Lookup\"))), \"ID\", \"Title\"), \"ID\", \"Id\", \"Title\", \"Value\"))<\/pre>\n<p>Third, click on the Lookup field in the form and change the <b>DefaultSelectedItems<\/b> to select the item from the list of options:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/default_selected_items.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/default_selected_items-1024x204.png\" alt=\"\" width=\"1024\" height=\"204\" class=\"aligncenter size-large wp-image-2193\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/default_selected_items-1024x204.png 1024w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/default_selected_items-300x60.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/default_selected_items-768x153.png 768w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/default_selected_items-1536x307.png 1536w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/default_selected_items.png 1898w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>The below formula returns an empty selection with <code>{Id:\"\", Value:\"\"}<\/code> when no URL param, otherwise it returns the first record for our lookup:<\/p>\n<pre class=\"brush:plain\">If(IsBlank(Param(\"Lookup\")), {Id:\"\", Value:\"\"}, First(RenameColumns(ShowColumns(Filter('DISTANT LIST NAME', ID = Value(Param(\"Lookup\"))), \"ID\", \"Title\"), \"ID\", \"Id\", \"Title\", \"Value\")))<\/pre>\n<p>And finally, we can pass <b>Lookup=ID<\/b> in the URL to select the related item in the other list<\/p>\n<h2>How to deal with new fields?<\/h2>\n<p>If you add a new field to your list&#8217;s settings, you&#8217;ll have to edit the form in PowerApps, and then edit the fields and add the new one:<br \/>\n<a href=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/add_field.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/add_field-1024x239.png\" alt=\"\" width=\"1024\" height=\"239\" class=\"aligncenter size-large wp-image-2197\" srcset=\"https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/add_field-1024x239.png 1024w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/add_field-300x70.png 300w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/add_field-768x179.png 768w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/add_field-1536x359.png 1536w, https:\/\/blog.kodono.info\/wordpress\/wp-content\/uploads\/2022\/11\/add_field.png 1906w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>(I used <a href=\"https:\/\/www.about365.nl\/2020\/08\/06\/passing-parameters-to-your-power-apps-sharepoint-form\/\">this article<\/a> as a starting point)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The only way to pass a URL parameter to a SharePoint Online (modern design) form&#8217;s field is to use PowerApps (at least, if you cannot add any JS on your website!). Important warning: when you use PowerApps to manage your form, all edits to the list settings won&#8217;t reflect to the PowerApps form. For example, [&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":[23,170,20],"tags":[156,123,155,117],"class_list":["post-2170","post","type-post","status-publish","format-standard","hentry","category-debug","category-english","category-niveau-expert","tag-debug","tag-english","tag-niveau-expert","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2170","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=2170"}],"version-history":[{"count":16,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2170\/revisions"}],"predecessor-version":[{"id":2198,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/2170\/revisions\/2198"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=2170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=2170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=2170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}