{"id":3126,"date":"2018-07-23T07:32:26","date_gmt":"2018-07-23T07:32:26","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=3126"},"modified":"2018-07-23T07:32:26","modified_gmt":"2018-07-23T07:32:26","slug":"getting-record-id-from-entityview-in-dynamics-365-portal","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=3126","title":{"rendered":"Getting Record Id from EntityView in Dynamics 365 Portal"},"content":{"rendered":"<p><strong>Introduction<\/strong>: We can use entity list to render records of entity from specific view configured in entity list. Entity list provide many options like sorting result set, re-labelling view columns, action buttons and more. We can configure details page in entity list which can be opened to view more details about the record or for edit\/updating. In this article we are going to discuss how we can get record details from entity list in Dynamics 365 portal using liquid.<\/p>\n<p><strong>Requirement<\/strong>: Let\u2019s say we have a requirement to open details page directly if entity list only contains one record and just show entity list only if we have more then 1 record. We are using Dynamics Portal trial for the demo purpose, if you want to setup trial portal check <a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/portals\/provision-portal\">this link<\/a><\/p>\n<p>We are going to use Customer Accounts entity list which is available on portal trial<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-3128 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts-300x144.png\" alt=\"customeraccounts\" width=\"300\" height=\"144\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts-300x144.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts-1024x492.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts-624x300.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts.png 1272w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Solution<\/strong>: We can implement above requirement with the help of the web template. In our web template we can write logic to retrieve data from the corresponding view (which is used for the entity list) and can check it\u2019s length like below<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n{% entityview logical_name:'account', name:&quot;Customer Accounts&quot; %}\r\n{% assign var_totalaccounts = entityview.total_records %}\r\n<\/pre>\n<p>In above code logical name is the entity associated to the entity list and name is the name of the view that we want to render under entity list in our web page. So in our case we are displaying list of the customer accounts. We are using total_records property to know total records returned by the view.<\/p>\n<p>Now we can put further check on the total accounts, if it is less than 2, we can navigate to the details page for account. To get columns we can use entityview object and use column logical name to retrieve it, in our example we need id field of the entity record so we can simply get it using entityview.records[0].id.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n{% if var_totalaccount &lt; 2 %}\r\n&lt;script&gt;\r\nwindow.location.href=&quot;\/customers\/customer-accounts\/edit-customer-account\/?id={{ entityview.records[0].id }}&quot;;\r\n&lt;\/script&gt;\r\n{% endif %}\r\n<\/pre>\n<p>Here is the final code for our web template.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n{% extends 'layout_1_column' %}\r\n{% block main %}\r\n  {% include 'page_copy' %}\r\n    {% if user %}\r\n    {% include 'entity_list' key:page.adx_entitylist.id %}\r\n  {% else %}\r\n\r\n&lt;div class='alert alert-block alert-info'&gt;\r\n\r\n&lt;span class='fa fa-info-circle'&gt;&lt;\/span&gt;{% editable snippets 'CustomerService\/Support\/SignIn' type: 'text', default: resx['CustomerService_Support_PleaseSignIn'], escape: true, tag: 'span' %}\r\n&lt;\/div&gt;\r\n\r\n  {% endif %}\r\n\r\n{% entityview logical_name:'account', name:&quot;Customer Accounts&quot; %}\r\n{% assign var_totalaccount = entityview.total_records %}\r\n\r\n{% if var_totalaccount &lt; 2 %}\r\n&lt;script&gt;\r\nwindow.location.href=&quot;\/customers\/customer-accounts\/edit-customer-account\/?id={{ entityview.records[0].id }}&quot;;\r\n&lt;\/script&gt;\r\n{% endif %}\r\n\r\n{% endentityview %}\r\n{% endblock %}\r\n<\/pre>\n<p>Let&#8217;s now create web template by navigating to Portals-&gt;Web Templates and use above code in code editor<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-3129 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts1-300x158.png\" alt=\"customeraccounts1\" width=\"300\" height=\"158\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts1-300x158.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts1-1024x541.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts1-624x330.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts1.png 1655w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Once web template is created we can create page template which will be using this web template, like below<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-3130 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts2-300x165.png\" alt=\"customeraccounts2\" width=\"300\" height=\"165\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts2-300x165.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts2-1024x564.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts2-624x344.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts2.png 1232w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Finally we need to set our new page template to the page which is rendering customer accounts entity list, like below<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-3131 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts3-300x196.png\" alt=\"customeraccounts3\" width=\"300\" height=\"196\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts3-300x196.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts3-1024x669.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts3-624x407.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/07\/customeraccounts3.png 1124w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now when you will navigate to Customer Accounts, it will direct navigate to detail page if customer accounts view have only one record, otherwise it will stay on entity list page to show customer accounts.<\/p>\n<p>Hope it will help someone !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: We can use entity list to render records of entity from specific view configured in entity list. Entity list provide many options like sorting result set, re-labelling view columns, action buttons and more. We can configure details page in entity list which can be opened to view more details about the record or for edit\/updating. In this article we&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=3126\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":3037,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[402,522,508],"tags":[559,558,560,557,561],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3126"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3126"}],"version-history":[{"count":4,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3126\/revisions"}],"predecessor-version":[{"id":3734,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3126\/revisions\/3734"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/3037"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}