I have been working on a Unified Service Desk implementation lately, and we had configured an Option with the url of the Dynamics instance that the user was connected to. This was limiting our ALM and did feel like technical debt in plain sight.
I wanted to find a solution that would help us remove this Option from our environments, one configuration less to manage.
If you want something advanced like that a Scriptlet was the obvious choice, but there is not much documentation online that helps you with Scriptlets.
You can reference Hosted Controls from a scriptlet (read more in Microsoft Docs). I would make sense for the Connection Manager control to have a reference of the Dynamics Instance it was connected so I went exploring the properties of Connection_Manager. Luckily scriptlets are some form of Javascript that is able to consume the dynamics .net SDK's public properties. I could not find some documentation for these properties so I went exploring with the help of the following trick in the script debugger:
function getProperties() {
var properties = [];
for(var property in Connection_Manager){
properties.push(property);
}
return properties.join(' ');
}
getProperties();Interesting, the CRM Interface property is a CrmServiceClient which has the property ConnectedOrgPublishedEndpoints that exposes the Api Endpoint, Data Endpoint and the Web Application Enpoint. We are interested on the latter.
There is one other limitation I had to workaround. The key for the ConnectedOrgPublishedEndpoints Dictionary is an enum type and it cannot be used from our scriptlet. The following is the scriptlet that can return the url of the Dynamics instance that the user is connected to:
function getOrganizationUrl() {
var endpoints = Connection_Manager.CrmInterface.ConnectedOrgPublishedEndpoints.GetEnumerator();
for(var i =0; i< Connection_Manager.CrmInterface.ConnectedOrgPublishedEndpoints.Count; i++){
endpoints.MoveNext();
if(endpoints.Current.Key.ToString()=='WebApplication'){
return endpoints.Current.Value;
}
}
}
getOrganizationUrl();