Showing posts with label Global functions. Show all posts
Showing posts with label Global functions. Show all posts

Sunday, October 18, 2009

Global Functions/Variables available in Dynamics CRM

Global Functions:
There are various global functions which provide information about the client system.


IsOnline: This will return if the form has been opened from an Online or Offline system. This could be helpful if you would want a particular feature to be made available in a specific mode only.

Example:
if (IsOnline())
{
alert("You are working online");
}

These above are available through scripting. If you would like to check this in your server side app, you need to add reference to the Microsoft.Crm.Outlook.Sdk
assembly. The assembly contains a class named CrmOutlookService that can be used to check the status of the Outlook client.

IsCrmClientLoaded: This will return if the Microsoft Dynamics CRM for Outlook client has been loaded by Microsoft Outlook

IsCrmClientOffline: This will return true if Microsoft Dynamics CRM for Outlook with offline Access is currently in offline mode

GenerateAuthenticationHeader:
When you call webservice through scripting, you need to pass the authentication information along with the SOAP header. This function returns the appropriate Microsoft Dynamics CRM authentication header based on each deployment type: on-premise, Internet-facing deployment (IFD), or Microsoft Dynamics CRM Online.

Example:

var soapBody = "<soap:Body>"+
"<Execute xmlns='http://schemas.microsoft.com/crm/2007/"+
"WebServices'>"+
"<Request xsi:type='WhoAmIRequest' />"+
"</Execute> </soap:Body>";
var soapXml = "<soap:Envelope " +
"xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' "+
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "+
"xmlns:xsd='http://www.w3.org/2001/XMLSchema'>";
soapXml += GenerateAuthenticationHeader();
soapXml += soapBody;
soapXml += "</soap:Envelope>";

PrependOrgName: The CRM URL by default adds the CRM Organization name when you browse CRM. It is important that if you are displaying a custom page in an IFRAME, the path to the page should also include the current Organization name. This function automatically determines the current organization name and adds it to generate the URL specific to the current organization.

Example:

var url = prependOrgName("/isv/app/myapp.aspx");
results: If you were logged into Contoso organization “/Contoso/isv/app/myapp.aspx”

Global Variables:
Some of the Global variables that can really come in handy are
1. SERVER_URL: This will return the base Server URL.
2. ORG_UNIQUE_NAME: This will return the unique text value of the organizations name. This is the same value to you also receive in custom forms if you set the PassParams to be true.