{"id":1801,"date":"2015-10-31T06:42:25","date_gmt":"2015-10-31T06:42:25","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=1801"},"modified":"2015-11-30T10:27:48","modified_gmt":"2015-11-30T10:27:48","slug":"image-gallery-utility-for-dynamics-crm","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=1801","title":{"rendered":"Image Gallery Utility for Dynamics CRM"},"content":{"rendered":"<p>In our earlier <a href=\"https:\/\/himbap.com\/blog\/?p=1442\">article<\/a> we have demonstrated how we can fetch images attached to notes, working on the same requirement we have enhanced our examples to develop an image gallery utility to see all the images attached to notes. Here is the complete code for this utility:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;!--This is a Image Gallery utility, which can be used with any entity which have\r\nrelationship with Notes, this web resource will show all the images attached to notes --&gt;\r\n    &lt; html &gt; &lt; head &gt;\r\n    &lt; style type = &quot;text\/css&quot; &gt;\r\n\r\n    .left - div {\r\n        display: inline - block;\r\n        cursor: pointer;\r\n    }\r\n    .right - div {\r\n        cursor: pointer;\r\n        display: inline - block;\r\n    } &lt; \/style&gt;  &lt; meta charset = &quot;utf-8&quot; &gt;\r\n    &lt; \/head&gt;&lt;body style=&quot;-ms-zoom: 1;&quot;&gt;\r\n    &lt; script src = &quot;..\/..\/ClientGlobalContext.js.aspx&quot; &gt; &lt; \/script&gt;\r\n    &lt; script src = &quot;..\/Script\/SDK.REST.js&quot; type = &quot;text\/javascript&quot; &gt; &lt; \/script&gt; &lt; script type = &quot;text\/javascript&quot; &gt;\r\n\/\/variables\r\nvar currentImage = 0;\r\nvar img = document.createElement(&quot;IMG&quot;);\r\nvar images = new Array;\r\nvar TotalImages = 0;\r\nvar SectionName;\r\nvar TabName;\r\ndocument.onreadystatechange = function() {\r\n        if (document.readyState == &quot;complete&quot;) {\r\n            \/\/get query parameters\r\n            var queryParam = GetGlobalContext().getQueryStringParameters().data;\r\n            var fields = queryParam.split(&quot;,&quot;);\r\n            TabName = fields[0];\r\n            SectionName = fields[1];\r\n            \/\/hide control in case form create\r\n            if (isformtypeCreate())\r\n                showImageGalery(TabName, SectionName, false)\r\n            else {\r\n                showImageGalery(TabName, SectionName, true)\r\n                getnotesImages();\r\n            }\r\n        }\r\n    }\r\n    \/\/check for form create mode\r\nfunction isformtypeCreate() {\r\n    if (window.parent.Xrm.Page.ui.getFormType() == 1) \/\/create mode\r\n        return true;\r\n    else\r\n        return false;\r\n}\r\n\/\/hide\/show image gallery\r\nfunction showImageGalery(tabname, sectionname, flag) {\r\n    window.parent.Xrm.Page.ui.tabs.get(tabname).sections.get(sectionname).setVisible(flag);\r\n}\r\n\/\/get images from notes\r\nfunction getnotesImages() {\r\n    var regardingObjectId = window.parent.Xrm.Page.data.entity.getId();\r\n    var entitySchemaName = &quot;Annotation&quot;;\r\n    var odataQuery = &quot;?$select=AnnotationId,DocumentBody,MimeType&amp;&quot; +\r\n        &quot;$filter=ObjectId\/Id eq guid'&quot; + regardingObjectId +\r\n        &quot;' and IsDocument eq true and startswith(MimeType,'image\/') &quot;;\r\n    if (typeof(SDK) != &quot;undefined&quot;) {\r\n        SDK.REST.retrieveMultipleRecords(entitySchemaName, odataQuery, getnotesImagesCallback, function(error) {\r\n            alert(error.message);\r\n        }, function() {});\r\n    } else {\r\n        alert(&quot;REST.SDK library is not available&quot;);\r\n    }\r\n}\r\n\/\/callback method\r\nfunction getnotesImagesCallback(resultSet) {\r\n    if (resultSet.length &gt; 0) {\r\n        TotalImages = resultSet.length;\r\n        for (i = 0; i &lt; resultSet.length; i++) {\r\n            var mimeType = resultSet[i].MimeType;\r\n            var body = resultSet[i].DocumentBody;\r\n            images[i] = &quot;data:&quot; + mimeType + &quot;;base64,&quot; + body;\r\n        }\r\n        changeImage(0);\r\n\r\n    } else\r\n        showImageGalery(TabName, SectionName, false);\r\n}\r\n\/\/change image\r\nfunction changeImage(counter) {\r\n      currentImage += counter;\r\n    if (currentImage != TotalImages) {\r\n        if (currentImage &lt; 0)\r\n            currentImage = 0;\r\n    } else {\r\n        currentImage = 0;\r\n    }\r\n    img.src = images[currentImage];\r\n    document.getElementById('imageGallery').appendChild(img);\r\n}\r\n\r\n&lt; \/script&gt; &lt; div &gt;\r\n\r\n&lt; input onclick = &quot;getnotesImages()&quot;\r\nalt = &quot;Reload&quot;\r\ntype = &quot;image&quot;\r\nsrc = &quot;..\/Image\/Refresh.png&quot; &gt;\r\n    &lt; input class = &quot;left-div&quot;\r\nalt = &quot;Go Next&quot;\r\nonclick = &quot;changeImage(-1);&quot;\r\ntype = &quot;image&quot;\r\nsrc = &quot;..\/Image\/Back.png&quot; &gt;\r\n    &lt; input class = &quot;right-div&quot;\r\nalt = &quot;Go Back&quot;\r\nonclick = &quot;changeImage(1);&quot;\r\ntype = &quot;image&quot;\r\nsrc = &quot;..\/Image\/Next.png&quot; &gt;\r\n    &lt; \/div&gt;  &lt; div id = &quot;imageGallery&quot;\r\nstyle = &quot;width: 100%; overflow: hidden;&quot; &gt;\r\n    &lt; \/div&gt;&lt;\/body &gt;\r\n    &lt; \/html&gt;\r\n<\/pre>\n<p>You can download complete utility from <a href=\"https:\/\/github.com\/himbap\/ClientSideUtilities\/releases\">GitHub <\/a><br \/>\nFollowing are the steps to use this Gallery<br \/>\n1. Download Solution from <a href=\"https:\/\/github.com\/himbap\/ClientSideUtilities\/releases\">here <\/a><br \/>\n2. Import this solution to your CRM environment (<em>We can place this web resource to any entity which has relationship with notes<\/em>)<br \/>\n3. Let\u2019s add this to account form, Open account entity form editor, and add a new section to existing tab or add a new tab and section to form.<br \/>\n4. Double click on tab and make note of tab name, follow similar steps for section and make note of section name, we need to pass these to web resource.<br \/>\n5. Select your section and click on Web Resource by navigating to insert tab under ribbon bar.<br \/>\n6. Select web resource properties like following:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imagegallery1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1802\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imagegallery1-300x288.png\" alt=\"Imagegallery1\" width=\"300\" height=\"288\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imagegallery1-300x288.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imagegallery1.png 571w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n7. Click on OK and save, publish your changes.<br \/>\n8. Open any account record and attach image using notes.<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imgegallery3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1811\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imgegallery3-300x96.png\" alt=\"Imgegallery3\" width=\"300\" height=\"96\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imgegallery3-300x96.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imgegallery3.png 537w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>9. Refresh your record first time to get image gallery, and you should be able to see it like below:<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imagegallery21.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1806\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imagegallery21-300x199.png\" alt=\"Imagegallery2\" width=\"300\" height=\"199\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imagegallery21-300x199.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Imagegallery21.png 387w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our earlier article we have demonstrated how we can fetch images attached to notes, working on the same requirement we have enhanced our examples to develop an image gallery utility to see all the images attached to notes. Here is the complete code for this utility: You can download complete utility from GitHub Following are the steps to use&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=1801\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,6,8],"tags":[243,241,242],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1801"}],"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=1801"}],"version-history":[{"count":14,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1801\/revisions"}],"predecessor-version":[{"id":1886,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1801\/revisions\/1886"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}