Sunday, 6 April 2014

Visual Studio 2012 Launch Problem : The Program can't start because MSVCR110.dll is missing from your computer. Try reinstalling the program to fix this problem


When you try to develop any plugin or anything in CRM and you need Visual Studio, sometimes you could face this problem when you launch the Visual Studio :

"The Program can't start because MSVCR110.dll is missing from your computer. Try reinstalling the program to fix this problem."


Then, the resolution is :

Go to this link :

http://www.microsoft.com/en-us/download/details.aspx?id=30679

Then download the file.


In my case after I resinstall the 64 bit, still cannot work eventhough my machine is Windows 64 bit, what I did is install both x64 and x86 version.


Hope it helps!

Set Default Price List in Opportunity Dynamics CRM 2011/2013 [No Hardcode]

I have this request when conducting a user requirement, my client said that When a new Opportunity Form is opened, the default price list will be automatically fill in the 'Price List' field.

This post I will give you a sample design and also the code to to this, and it should be working both in CRM 2011 or CRM 2013.

This is what user wants :




Without having effort to choosing default price list, they want to it can be filled in automatically.

There are many ways to do it, for example using the hardcode, by filling the lookup value to Price List with the hardcode Guid retrieved from 'Default Price List' record ID, but it will be a problem if they want to change the Default Price List or if you create another organization which is to the Guid of that can be different.

You should have knowledge about Javascript Form Scripting and oData, but don't worry, I will give you the way.

So my Design is to create a Price List record to be set as Default Price List (dynamically), then only keep one default price list for each Organization.

Steps :

1. Customize the Price List entity, create new field radio button and then place it to the Opportunity form.



NB : I give field name : "new_setasdefault"

2. Attach a Form OnSave function to Price List with JavaScript :


var isDuplicate = 0;

function PreventMultipleDoubleDefaultPriceList(context)
{

 //if field set as default == True
 if(Xrm.Page.getAttribute("new_setasdefault").getValue() == 1)
 {
  //check duplicate default Price List
  checkDuplicateDefaultPriceListId();
  if (isDuplicate == 1)
  {
         context.getEventArgs().preventDefault();
   }
 }
              

}


function checkDuplicateDefaultPriceListId()
{
       var oDataOrgURL = Xrm.Page.context.prependOrgName("/xrmservices/2011/organizationdata.svc");
 var currentId = Xrm.Page.data.entity.getId();

     var currentIdCondition = '';   
     if (currentId != null)
      {
         currentIdCondition = ' and PriceLevelId ne guid\'' + currentId + '\'';
      }


 //add filter
 var oDataURL = oDataOrgURL + "/PriceLevelSet?&$filter=(new_SetAsDefault eq true)" + currentIdCondition ;

 //call
 var defaultPriceListRequest = new XMLHttpRequest();   

     defaultPriceListRequest.open("GET", oDataURL , false);   
     defaultPriceListRequest.setRequestHeader("Accept", "application/json");   
     defaultPriceListRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8"); 
     defaultPriceListRequest.onreadystatechange = function () {       
            getDefaultPriceListIdCallBack(this); 
      }; 
     defaultPriceListRequest.send(null);
}

function getDefaultPriceListIdCallBack(retrievedDefaultPriceList)
{ 
         if (retrievedDefaultPriceList.readyState == 4 /* complete */)
         {
                 if (retrievedDefaultPriceList.status == 200)
                 {
                       var retrievedRecords = eval('(' + retrievedDefaultPriceList.responseText + ')').d;           
                       if(retrievedRecords.results.length > 0)
             {
                  var defaultPriceList = retrievedRecords.results[0];
                  alert("There is already Price List set as default : '" + defaultPriceList.Name + "', you can only have one Default Price List at the same time.");
                                isDuplicate = 1;
                                             }       
                 }       
                 else    {}       
                        //alert("Error occured"); 
          }
}

function SetLookup(fieldName, idValue, textValue, typeValue)
{
    var value = new Array();
    value[0] = new Object();
    value[0].id = idValue;
    value[0].name = textValue;
    value[0].typename = typeValue;

    Xrm.Page.getAttribute(fieldName).setValue(value);
}


Then call your function for OnSave event handler.



This function is purposely used to prevent more than one default price list.



3. Customize the Opportunity form by attaching this Javascript onLoad :

function fillDefaultPriceListOnLoad()
{
 //get form type 
 var formType = Xrm.Page.ui.getFormType();
 if(formType == 1) //if on create
 {
  getDefaultPriceListId();
 }
}

function getDefaultPriceListId()
{
 var oDataOrgURL = Xrm.Page.context.prependOrgName("/xrmservices/2011/organizationdata.svc");
  
 //add filter
 var oDataURL = oDataOrgURL + "/PriceLevelSet?$filter=new_SetAsDefault eq true";
 
 //call
 var defaultPriceListRequest = new XMLHttpRequest();     

     defaultPriceListRequest.open("GET", oDataURL, false);    
     defaultPriceListRequest.setRequestHeader("Accept", "application/json");    
     defaultPriceListRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");  
     defaultPriceListRequest.onreadystatechange = function () {        
            getDefaultPriceListIdCallBack(this);   
      };   
     defaultPriceListRequest.send(null); 
}

function getDefaultPriceListIdCallBack(retrievedDefaultPriceList) 
{   
         if (retrievedDefaultPriceList.readyState == 4 /* complete */) 
         {
                 if (retrievedDefaultPriceList.status == 200) 
                 {
                       var retrievedRecords = eval('(' + retrievedDefaultPriceList.responseText + ')').d; ;            
                       if(retrievedRecords.results.length > 0)
             {
                  var defaultPriceList = retrievedRecords.results[0];
                  SetLookup("pricelevelid", defaultPriceList.PriceLevelId, defaultPriceList.Name, 

"pricelevel");
             }        
                 }        
                 else            
                        alert("Error occured");   
          }
} 

function SetLookup(fieldName, idValue, textValue, typeValue)
{
    var value = new Array();
    value[0] = new Object();
    value[0].id = idValue;
    value[0].name = textValue;
    value[0].typename = typeValue;

    Xrm.Page.getAttribute(fieldName).setValue(value);
}

Then call the function on Opportunity Form onLoad event handler.



Then we can achieve what user wants without any hardcode, but using parameter and configuration.

This is the result in CRM 2013



I can give you the solution if you want.

Hope it helps!
Thanks.