I want to pass formcontext to a html WebEesource, so that it can update a few fields in a model driven form.
Unfortunately in my TypeScript, it is none too happy with .getContentWindow() as in it is not available. So am I missing a type or need to do a magic cast.?
Also this snippet won't know about the JavaScript functions in the Html WebResource so that is also an issue to solve🤔.
function onFormLoad(executionContext : Xrm.Events.EventContext)
{
const formContext = executionContext.getFormContext();
const webResourceName = "myproj_lookup.html";
let webResourceControl = formContext.getControl<(webResourceName);
// add a bit fo debugging code
let globalContext = Xrm.Utility.getGlobalContext();
let webResourceUrl = globalContext.getWebResourceUrl(webResourceName);
if (webResourceUrl)
{
// this shows the actual url
console.log("Web Resource Url: " + webResourceUrl);
}
if (webResourceControl) {
webResourceControl.getContentWindow().then(
function(contentWindow) {
// Call your function to pass Xrm and formContext
contentWindow.setClientApiContext(Xrm, formContext);
});
}
else
{
// this what I am seeing :-(
console.log("Web Resource not found")
}
}