Sunday, December 16, 2012

Dynamics CRM 2011 - Preventing close alert

Dynamics CRM 2011 - Preventing close alert


In Dynamics CRM 4.0 it was easy to disable close alert by using this one line of code before you close the window:
crmForm.detachCloseAlert();

In Dynamics CRM 2011, this method is depracated. The way i workaround it, is setting all dirty fields submit mode to never.
function IsAttributeDirty(attribute, index) {    return attribute.getIsDirty();}
function SetAllDirtyFieldsToNeverSubmit(){ var attributes = Xrm.Page.data.entity.attributes.get(IsAttributeDirty); for (var i in attributes) { attributes[i].setSubmitMode("never"); }}//ends function RemoveAllDirtyFields(){
Close window with out fields change message:
SetAllDirtyFieldsToNeverSubmit();
Xrm.Page.ui.close();

Sunday, December 9, 2012

Microsoft Dynamics CRM 2011 - Something about plugins SharedVariables

Microsoft Dynamics CRM 2011 - Something about plugins SharedVariables

My SharedVariables problem 
I had 2 plugins:
1) Pre Validation (code: 10)
2) Post Operation (code: 40)
After adding new value to SharedVariables in PreValidation, I've failed getting it in the PostOperation.

Solution:
I've found this article which explains the subject very well and helped me with my issue:
http://thomasthankachan.com/2011/08/12/pass-data-between-plug-ins-using-sharedvariables/

Summary:
PreValidation and PostOperation are running under different pipelines, and you should get SharedVariables from the parent context in PostOperation plugin and not it's own context.

MyCode:


bool isUpdate = true;
if(context.SharedVariables.Contains("SkipPlugin") && ((bool) context.SharedVariables["SkipPlugin"]))
{
  isUpdate = false;
} else if(context.ParentContext != null && context.ParentContext.SharedVariables.Contains("SkipPlugin") && ((bool) context.ParentContext.SharedVariables["SkipPlugin"])) {
  isUpdate = false;
}