Friday, 27 February 2015

CRM 2015 - Javascript - Execution Context

 This one can be quite interesting, the possibility of interacting with data from a plugin trough the Javascript, for now, i'm not seeing any example, but definitively is one to have a look, and what i think is quite interesting is regarding with  getSharedVariable and  setSharedVariable.


When you associate a function in a JavaScript library to an event handler in Microsoft Dynamics CRM, you can check the   Pass execution context as first parameter   option. The following table lists the execution context object methods. 

  

Method Description 

getContext 

Returns the   Xrm.Page.context   object. See   Client-side context (client-side reference)   for more information. 

getDepth 

Returns a value indicating the order in which this handler is executed. 

getEventSource 

Returns a reference to the object that the event occurred on. 

getSharedVariable 

Retrieves a variable set using   setSharedVariable 

setSharedVariable 

Sets the value of a variable that can be used by a hander after the current handler finishes. 

Use the   getEventSource   method in functions to make them more generic. For example, if you have a function that formats a telephone number, you can use the   getEventSource   method to refer to whatever attribute caused the   onChange   event. Your functions do not need to reference a specific attribute. 


Hope it gives you new ideas to extend even more CRM. 

Thursday, 26 February 2015

CRM 2015 – Web Service Error Codes

 Below is a link to the Microsoft page with all the error codes and descriptions that can be thrown by CRM web services.  

<crmerror>
<ErrorId>80048531</ErrorId>
<ManagedErrorName>CustomImageAttributeOnlyAllowedOnCustomEntity</ManagedErrorName>
<ErrorMessage>A custom image attribute can only be added to a custom entity.</ErrorMessage>
</crmerror>
<crmerror>
<ErrorId>80048530</ErrorId><ManagedErrorName>SqlEncryptionSymmetricKeyCannotOpenBecauseWrongPassword</ManagedErrorName>
<ErrorMessage>Cannot open encryption Symmetric Key because the password is wrong.</ErrorMessage>
</crmerror>


Hope it helps.

Wednesday, 25 February 2015

CRM 2015 - Common Exceptions

Developing around CRM always we have to catch Exceptions (Business Exceptions provoked on purpose by our code, sometimes we have to ), below a few examples for the common exceptions.

catch (FaultException ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp);
Console.WriteLine("Code: {0}", ex.Detail.ErrorCode);
Console.WriteLine("Message: {0}", ex.Detail.Message);
Console.WriteLine("Inner Fault: {0}",
null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
}
catch (System.TimeoutException ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine("Message: {0}", ex.Message);
Console.WriteLine("Stack Trace: {0}", ex.StackTrace);
Console.WriteLine("Inner Fault: {0}",
null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine(ex.Message);
// Display the details of the inner exception.
if (ex.InnerException != null)
{
Console.WriteLine(ex.InnerException.Message);
FaultException fe = ex.InnerException
as FaultException;
if (fe != null)
{
Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp);
Console.WriteLine("Code: {0}", fe.Detail.ErrorCode);
Console.WriteLine("Message: {0}", fe.Detail.Message);
Console.WriteLine("Trace: {0}", fe.Detail.TraceText);
Console.WriteLine("Inner Fault: {0}",
null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
}
}
}

Hope it helps.

Monday, 23 February 2015

CRM 2015 - Javascript - Display Notifications

 Below a table with the ways to display notifications using the CRM objects.

Task
Example
Display a message near the control to indicate that data is not valid.
Xrm.Page.getAttribute("name").controls.forEach(
function (control, i) {
control.setNotification("'Test' is not a valid name.");
})
Sets a validation error message on every control in the form for the Account Nameattribute.
While this message is displayed the record cannot be saved.
This method is only available for Updated entities.
Remove a message already displayed for a control.
Xrm.Page.getAttribute("name").controls.forEach(
function (control, i) {
control.clearNotification();
}) 
Clears all validation error messages on every control in the form for the Account Nameattribute.
This method is only available for Updated entities.
Display form level notifications.
Xrm.Page.ui.setFormNotification(
"Hello",
"INFO",
"helloMsg"
); 
Displays the message “Hello” at the top of the form with a system info icon.
This method is only available for Updated entities.
Remove form level notifications
Xrm.Page.ui.clearFormNotification("helloMsg"); 
Clears the message previously set using “helloMsg” as the uniqueid parameter.
This method is only available for Updated entities.
Display a non-blocking alert dialog with a callback function.
var alertDisplayed = false;
Xrm.Utility.alertDialog(
"Showing Alert",
function () { alertDisplayed = true; }
)
Display an alert and set the value of the alertDisplayed variable when it is closed.
This method is only available for Updated entities.
Display a non-blocking confirm dialog with different callbacks depending on the button clicked by the user.
var agree = false;
Xrm.Utility.confirmDialog(
"Do you agree?",
function () { agree = true;},
function () { agree = false; }
);
Display a confirmation message and set the value of the agree variable depending on the response.
This method is only available for Updated entities.

Hope t helps.

CRM 365 Cloud - Disassociate 2 records using typescript

In case you need to Disassociate 2 records, please find below the code that allows you to do that.      export async function DissociateE...