Customer Engagement & Dynamics CRM Forum

Expand all | Collapse all

Custom HTML Web Resource in Unified Interface - Parameter Passing

  • 1.  Custom HTML Web Resource in Unified Interface - Parameter Passing

    Posted Apr 04, 2019 02:26 AM

    Hello everyone,

    We have a custom web page (HTML, Angular Javascript & CSS are in separate web resource files ) that is published via a web resource.

    This custom page works in our v9.1 environment on the standard web interface, however, under the unified interface the page does not work correctly - CSS is not applied and no data is retrieved by the angular based javascript.  The HTML page is opened from a button on the Contact record menu bar.

    In the console the error shows as:

    TypeError: Cannot read property 'replace' of undefined
    at Object.<anonymous> (ManageReportAccess.html&orgname=QIC Limited DEVELOPMENT&userlcid=1033&orgname=1033:286)
    at Object.invoke (angular.js:5106)
    at O.instance (angular.js:11076)
    at p (angular.js:9939)
    at f (angular.js:9248)
    at angular.js:9113
    at angular.js:1960
    at m.$eval (angular.js:18542)
    at m.$apply (angular.js:18641)
    at angular.js:1958
    (anonymous) @ angular.js:14800

    And the code referenced by the error message (last line highlighted) in the HTML file is:

    crmApp.controller('crmContactController', ['$scope','$q','crmAccountReportService', function($scope,$q,crmAccountReportService) { 
    var _urlParams = getUrlParams();
    var _selectedId = _urlParams.id.replace(/{|}/g,"");


    According to Microsoft Support the use of a custom web page web resource is supported, but I need some direction in passing the parameters necessary for the web page.  Any guidance would be appreciated.

    Michael



    ------------------------------
    Michael Thorne
    QIC Limited
    ------------------------------
    CRMUG Summit - Post


  • 2.  RE: Custom HTML Web Resource in Unified Interface - Parameter Passing

    GOLD CONTRIBUTOR
    Posted Apr 04, 2019 10:27 AM
    Michael,
    I would recommend to post code of getUrlParams function. I experienced similar issue with passing of parameters specifically in UCI (everything worked for years in WebClient) that I described here - https://butenko.pro/2018/12/07/html-webresource-classic-ui-vs-uci-story-of-broken-functionality/

    ------------------------------
    Andrew Butenko
    ------------------------------

    CRMUG Summit - Post


  • 3.  RE: Custom HTML Web Resource in Unified Interface - Parameter Passing

    Posted Apr 04, 2019 05:42 PM
    Hi Andrew,

    Thanks for replying so quickly.

    Here is the section requested:

    	<script type="text/javascript">	
    		function getUrlParams(variable) {
    			var pairs = [];
                var params = window.location.search.substring(1).split("&");
    			
                for (var i = 0; i < params.length; i++) {
                    var param = params[i].split("=");
                   if (param[0]) { 
    					pairs[param[0].toLowerCase()] = decodeURIComponent(param[1]); 
    					pairs.push({key:param[0],value:param[1]});
    				}
                }
                return pairs;
            }


    Thanks for any insight you can provide.


    Michael



    ------------------------------
    Michael Thorne
    QIC Limited
    ------------------------------

    CRMUG Summit - Post


  • 4.  RE: Custom HTML Web Resource in Unified Interface - Parameter Passing

    GOLD CONTRIBUTOR
    Posted Apr 04, 2019 10:25 PM
    Hello,
    Can you please add alert(window.location.search) to your getUrlParams method and run it in UCI, copy output and post here for investigation.

    ------------------------------
    Andrew Butenko
    ------------------------------

    CRMUG Summit - Post


  • 5.  RE: Custom HTML Web Resource in Unified Interface - Parameter Passing

    TOP CONTRIBUTOR
    Posted Apr 05, 2019 03:40 PM
    Michael

    Your function returns an array of key value pairs, not an object.

    If you want the value of id then you need to use the array.find

    getUrlParams.find(x => {return x.key == "id"}).value

    And since this is a webresource then your value is probably still encoded.

    decodeURIComponent(getUrlParams(x).find(x => {return x.key == "id"}).value).replace(/{|}/g,"")

    Cheers!


    ------------------------------
    Rex Kenley Tan, MCP
    Tallmadge OH
    https://www.youracclaim.com/users/rex-kenley-tan

    *Always be CURRENT with JavaScript & C#, NEVER be obsolete.

    DISCLAIMER: All views expressed on this site are my own and DO NOT represent the opinions of ANY entity whatsoever with which I have been, am now, or will be affiliated.
    ------------------------------

    CRMUG Summit - Post


  • 6.  RE: Custom HTML Web Resource in Unified Interface - Parameter Passing

    Posted 8 days ago
    I've been looking into this issue again.

    I noticed that on the button in the ribbon the Pass Parameters option was set.  This (appears) to force the form to issue some default set of parameters which appear to change depending whether its classic UI or the new UI.

    So I manually added to the ribbon settings the set of parameters passed by the classic UI when the Pass Parameters option is turned on.  Published the changes into CRM and refreshed my CRM session.

    As expected, in the classic UI the parameters were passed, can be seen in the URL and the form works.

    If I do the same from the new Unified Interface the the parameters are NOT passed, can NOT be seen in the URL and the form, is of course, not working.

    Can anyone explain why the parameters defined in the ribbon are not being passed to the HTML web resource?

    As a test I created a simple "Hello World" html page as a web resource and substituted it.  Once again all the parameters appeared in the URL of the classic UI launched web page, and were missing from the new Ui launched web page.

    Thanks,

    Michael

    ------------------------------
    Michael Thorne
    QIC Limited
    ------------------------------

    CRMUG Summit - Post


  • 7.  RE: Custom HTML Web Resource in Unified Interface - Parameter Passing

    TOP CONTRIBUTOR
    Posted 8 days ago
    Edited by Rex Kenley Tan 8 days ago

    Michael


    Since I am working in the dark without any code, my best guess is that you're using a deprecated function.

    The formContext.data.attributes API will make retrieval of non-entity bound data consistent across entity forms, metadata-driven dialogs, and task-based flows. The data will be a combination of custom values sent using the query string and what was specified in the parameters in the openForm method.

    https://docs.microsoft.com/en-us/dynamics365/get-started/whats-new/customer-engagement/important-changes-coming

    Cheers!



    ------------------------------
    Rex Kenley Tan, MCSA: Web Applications
    Tallmadge OH
    https://www.youracclaim.com/users/rex-kenley-tan

    *Always be CURRENT with JavaScript & C#, NEVER be obsolete.

    DISCLAIMER: All views expressed on this site are my own and DO NOT represent the opinions of ANY entity whatsoever with which I have been, am now, or will be affiliated.
    ------------------------------

    CRMUG Summit - Post


  • 8.  RE: Custom HTML Web Resource in Unified Interface - Parameter Passing

    Posted 7 days ago
    Hi Ray,

    The code for my temporary web page is as follows:

    <html>
    <head>
    <meta>
    </head>
    <body onfocusout="parent.setEmailRange();" style="overflow-wrap: break-word;">
    <font size="6" face="Arial">Hello World!</font>
    </body>
    </html>

    I have attached screen captures of the output (highlighting how the parameters have not been passed in the new UI launch) and the ribbon commands.

    Thanks for the assistance.

    ------------------------------
    Michael Thorne
    QIC Limited
    ------------------------------

    CRMUG Summit - Post


  • 9.  RE: Custom HTML Web Resource in Unified Interface - Parameter Passing

    TOP CONTRIBUTOR
    Posted 7 days ago
    Edited by Rex Kenley Tan 7 days ago

    Michael

    Is your Ribbon Workbench version 3.1.177? If so, are you using the new method, formContext.data.attributes, to get the values?

    Getting the formContext object for JavaScript functions for ribbon actions is different from how you get it in form scripting. More information: Form and grid context in ribbon actions.

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/clientapi-form-context

    ------------------------------
    Rex Kenley Tan, MCSA: Web Applications
    Tallmadge OH
    https://www.youracclaim.com/users/rex-kenley-tan

    *Always be CURRENT with JavaScript & C#, NEVER be obsolete.

    DISCLAIMER: All views expressed on this site are my own and DO NOT represent the opinions of ANY entity whatsoever with which I have been, am now, or will be affiliated.
    ------------------------------

    CRMUG Summit - Post


If you've found this thread useful, dive deeper into User Group community content by role