Skip to content

Commit 6cbe3dc

Browse files
committed
Split GetClientUrl into smaller functions to hopefully reduce code-complexity
1 parent 0d0d96f commit 6cbe3dc

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,30 +1305,62 @@ namespace XQW {
13051305
* @internal
13061306
*/
13071307
function getClientUrl() {
1308+
const url = getClientUrlFromGlobalContext()
1309+
|| getClientUrlFromUtility()
1310+
|| getClientUrlFromXrmPage()
1311+
1312+
if (url) {
1313+
return url;
1314+
}
1315+
1316+
throw new Error("Context is not available.");
1317+
}
1318+
1319+
/**
1320+
* @internal
1321+
*/
1322+
function getClientUrlFromGlobalContext() {
13081323
try {
13091324
if (GetGlobalContext && GetGlobalContext().getClientUrl) {
1310-
return GetGlobalContext().getClientUrl();
1325+
return GetGlobalContext().getClientUrl() as string;
13111326
}
13121327
} catch (e) {}
1328+
1329+
return undefined;
1330+
}
1331+
1332+
/**
1333+
* @internal
1334+
*/
1335+
function getClientUrlFromUtility() {
13131336
try {
13141337
if (Xrm && Xrm.Utility && Xrm.Utility.getGlobalContext) {
1315-
return Xrm.Utility.getGlobalContext().getClientUrl();
1338+
return Xrm.Utility.getGlobalContext().getClientUrl() as string;
13161339
}
13171340
} catch (e) {}
13181341
try {
13191342
if (window && window.parent && window.parent.window) {
13201343
const w = <typeof window & { Xrm: any; }>(window.parent.window);
13211344
if (w && w.Xrm && w.Xrm.Utility && w.Xrm.Utility.getGlobalContext) {
1322-
return w.Xrm.Utility.getGlobalContext().getClientUrl();
1345+
return w.Xrm.Utility.getGlobalContext().getClientUrl() as string;
13231346
}
13241347
}
13251348
} catch (e) {}
1349+
1350+
return undefined;
1351+
}
1352+
1353+
/**
1354+
* @internal
1355+
*/
1356+
function getClientUrlFromXrmPage() {
13261357
try {
13271358
if (Xrm && Xrm.Page && Xrm.Page.context) {
1328-
return Xrm.Page.context.getClientUrl();
1359+
return Xrm.Page.context.getClientUrl() as string;
13291360
}
13301361
} catch (e) {}
1331-
throw new Error("Context is not available.");
1362+
1363+
return undefined;
13321364
}
13331365

13341366
/**

0 commit comments

Comments
 (0)