I'm encountering an issue attempting to reference javascript functions from Dynamics 365 forms when the javascript files have been compiled from typescript that is exporting the class the function resides in (which I'm doing in order to run unit tests against them). The same problem does not occur if i put the function in a namespace instead, but it does if i then try to export the namespace instead/aswell as the function (again to be able to be reference in unit tests.
In each of the cases below, inside Dynamics in the onchange event I am referencing the function to be called by Referral.OpenDialogOnHold.
So when using:
export class Referral {
static OpenDialogOnHold(context: Xrm.Events.EventContext) {
try {
Xrm.Navigation.navigateTo(
...
);
} catch (exception) {
console.error(exception);
}
}
}
or
export namespace Referral {
export function OpenDialogOnHold(context: Xrm.Events.EventContext) {
try {
Xrm.Navigation.navigateTo(
...
);
} catch (exception) {
console.error(exception);
}
}
}
then it fails inside Dynamics saying it cannot find the function names Referral.OpenDialgOnHold
but if I use:
namespace Referral {
export function OpenDialogOnHold(context: Xrm.Events.EventContext) {
try {
Xrm.Navigation.navigateTo(
...
);
} catch (exception) {
console.error(exception);
}
}
}
then it works fine, however I'm then struggling to reference the function within unit tests as it complains the file is not a module.
Any assistance gratefully appreciated!
ts.config settings are:
{
"compileOnSave": true,
"compilerOptions": {
"target": "ES5",
"module": "ES2015",
"rootDir": "ts",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "Webresources/ih_/js",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": ["tests/**/*"]
}