Skip to content

Commit 847a181

Browse files
authored
Merge pull request #194 from delegateas/getclienturl
Update getClientUrl function to support Xrm.Utility
2 parents b31c8c4 + 789b702 commit 847a181

1 file changed

Lines changed: 47 additions & 3 deletions

File tree

src/XrmDefinitelyTyped/Resources/dg.xrmquery.web.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,17 +1305,61 @@ namespace XQW {
13051305
* @internal
13061306
*/
13071307
function getClientUrl() {
1308+
let url = getClientUrlFromGlobalContext();
1309+
if (url !== undefined) return url;
1310+
url = getClientUrlFromUtility();
1311+
if (url !== undefined) return url;
1312+
url = getClientUrlFromXrmPage();
1313+
if (url !== undefined) return url;
1314+
1315+
throw new Error("Context is not available.");
1316+
}
1317+
1318+
/**
1319+
* @internal
1320+
*/
1321+
function getClientUrlFromGlobalContext() {
13081322
try {
13091323
if (GetGlobalContext && GetGlobalContext().getClientUrl) {
1310-
return GetGlobalContext().getClientUrl();
1324+
return GetGlobalContext().getClientUrl() as string;
1325+
}
1326+
} catch (e) {}
1327+
1328+
return undefined;
1329+
}
1330+
1331+
/**
1332+
* @internal
1333+
*/
1334+
function getClientUrlFromUtility() {
1335+
try {
1336+
if (Xrm && Xrm.Utility && Xrm.Utility.getGlobalContext) {
1337+
return Xrm.Utility.getGlobalContext().getClientUrl() as string;
13111338
}
13121339
} catch (e) {}
1340+
try {
1341+
if (window && window.parent && window.parent.window) {
1342+
const w = <typeof window & { Xrm: any; }>(window.parent.window);
1343+
if (w && w.Xrm && w.Xrm.Utility && w.Xrm.Utility.getGlobalContext) {
1344+
return w.Xrm.Utility.getGlobalContext().getClientUrl() as string;
1345+
}
1346+
}
1347+
} catch (e) {}
1348+
1349+
return undefined;
1350+
}
1351+
1352+
/**
1353+
* @internal
1354+
*/
1355+
function getClientUrlFromXrmPage() {
13131356
try {
13141357
if (Xrm && Xrm.Page && Xrm.Page.context) {
1315-
return Xrm.Page.context.getClientUrl();
1358+
return Xrm.Page.context.getClientUrl() as string;
13161359
}
13171360
} catch (e) {}
1318-
throw new Error("Context is not available.");
1361+
1362+
return undefined;
13191363
}
13201364

13211365
/**

0 commit comments

Comments
 (0)