The issue
After changing to a new UI a custom web resource launched from a custom button of the ribbon bar stopped receiving parameters.
This leads to the incorrect page layout generation and other issues which are based on the missing parameter.
The diagnostics
There are things to consider while performing re-work on the page:
- The Command selected to launch the web resource is not the best solution according to the best practice. We will replace the URL command with JavaScript .
- The latest CRM forms scripting framework changes have to be accommodated
- The way to pass parameters from the parent form to the web resource should be the working scenario for both UIs, old and new.
POC
This is how it’s gonna work after we implement the proof of concept:
Old UI
Pay attention to the query string. “Data” parameter contains entityId.
New UI
And here for the query string “data” parameter contains entityId.
The solution
1)Create a JavaScript library with a function as per the screen below:
var PO = window.PO || {}; PO.openHTML = function (primaryControl, commonProperties) { var formContext =primaryControl; if(formContext == null) return; var id = formContext.data.entity.getId(); Xrm.Navigation.openWebResource("po_test.html",null, id); };
2)Add the library to the Account form:
3)For the Account entity form ribbon using RibbonWorkbench change the Command type on Ribbon bar button to JavaScript. Add the library and the function references from the steps above. Add a CRM Parameter = PrimaryControl.
3)My test HTML code. The bit to highlight here is the parameter storing a record Id for old UI is “Data” and for new one “data”. We use .toLowerCase() function to manage this fact.
<html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> http://../ClientGlobalContext.js.aspx http://scripts/es6promise.js http://scripts/WebAPIFunctionsAndActions.js function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split('&'); for (var i = 0; i decodeURIComponent(pair[0]).toLowerCase() == variable.toLowerCase()) { return decodeURIComponent(pair[1]); } } alert('Query variable %s not found', variable); } alert(getQueryVariable("data")); </head> <body lang="en-US" style="overflow-wrap: break-word;"> <h1>Test</h1> </body> </html>