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 17 days ago

    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
    ------------------------------


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

    GOLD CONTRIBUTOR
    Posted 16 days ago
    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
    ------------------------------



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

    Posted 16 days ago
    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
    ------------------------------



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

    GOLD CONTRIBUTOR
    Posted 16 days ago
    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
    ------------------------------



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

    TOP CONTRIBUTOR
    Posted 15 days ago
    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.
    ------------------------------



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