if (typeof North52 == 'undefined') { North52 = {}; }
if (typeof North52.DeploymentSolution == 'undefined') { North52.DeploymentSolution = {}; }


North52.DeploymentSolution.Load = function() {  

  try
{
          
     if (parent.Xrm.Page.ui.getFormType() != 6)
     {

       $("#formulaDeploymentSolution").hide();
       $("select[id$=formulaDeploymentSolution] > option").remove();

        var options= "$select=FriendlyName,UniqueName&$filter=IsManaged eq false and IsVisible eq true and UniqueName ne 'Default'&$orderby= FriendlyName asc";

        SDK.REST.retrieveMultipleRecords("Solution", options, North52.DeploymentSolution.RetrieveEntityData, function (error) { window['n52error'] = error; window['executionContext'] = null; alert("North52 Formula Manager: An error has occurred please contact your system administrator."  ); }, North52.DeploymentSolution.RetrieveComplete);
       }
   
 }
 catch(ex)
 {
    alert('North52 Formula Manager: Communication issue, please click Ok & then F5 to refresh the screen. Message: ' + ex.message);

 }
        
   
  };





North52.DeploymentSolution.RetrieveEntityData = function(data) {  

try
 {

    for (var i = 0; i < data.length; i++)
    {
      N52.HTMLWebResourceHelper.InsertOptionSetItem("formulaDeploymentSolution", data[i].FriendlyName, data[i].UniqueName);    
     }

       var savedSolution = parent.Xrm.Page.getAttribute("north52_deploymentsolution").getValue();

    if (savedSolution !== null && savedSolution !=="") 
    {  
            $("#formulaDeploymentSolution").val(savedSolution);
      }
      else
      {
         $("#formulaDeploymentSolution").val('North52FormulaManagerDeploymentSolution');
         parent.Xrm.Page.data.entity.attributes.get("north52_deploymentsolution").setValue("North52FormulaManagerDeploymentSolution");

      }

   $('#loading-formuladeploymentsolution').hide(); 
   $('#formulaDeploymentSolution').show(); 

 }
 catch(ex)
 {
   alert('North52 Formula Manager: Communication issue, please click Ok & then F5 to refresh the screen. Message: ' + ex.message);
 }
 

  };


North52.DeploymentSolution.DropDownChanged= function(value) {  


  try
  {
    if (value != null && value!="")
    {  
       parent.Xrm.Page.data.entity.attributes.get("north52_deploymentsolution").setValue(value);
     }

   }
   catch(ex)
   {
      alert('North52 Formula Manager: Communication issue, please click Ok & then F5 to refresh the screen. Message: ' + ex.message);
   }
} ; 

North52.DeploymentSolution.RetrieveComplete= function(value) {  


         var msg = 'Complete';
  };
