Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Adding a Calculated Field

$
0
0

Good afternoon, we have a customm form that I need to add a calculated field to.

The following code is in the frmOnLoad event of the form. When I run the form I get 'Xrm' is not defined.

Its in the FWeightedValue  function below

Can anyone decipher this form me....Thanks in advance

frmOnLoad();
 onLoad = false;

}
catch(e)
{ alert(e.message); }
}//End of if condition
}//End of function

/* Declare Variables */
var onLoad = true;
var sGlobalVar = '';


function frmOnLoad()
{ ResizeScreen();
 AddLogoToFormTitle(160, "/CRM4Legal/_imgs/reznick_small.gif");

 fldMerge('name');
 fldMerge('customerid');
 fldMerge('rg_officeid');

 fldStatus();
 fldGSMC();
 frmTabs();
 frmNav();
 frmIFrames();
                     // FWeightedValue();

 if ($("rg_gsmc"  ) != null) $("rg_gsmc" ).onclick = fldGSMC;

 {
  if (typeof FWeightedValue == "undefined") {
   FWeightedValue = {};
  }

  FWeightedValue = function () {
   var EstRev = Xrm.Page.getAttribute("estimatedvalue").getValue();
   var RiskWeight = Xrm.Page.getAttribute("cpdc_riskweight").getValue();
   var RiskPercent = RiskWeight / 100;
   var RiskWeightValue = FWeightedValue.NullCheck(EstRev) * FWeightedValue.NullCheck(RiskPercent);

   Xrm.Page.getAttribute("cpdc_riskweightedvalue").setValue(RiskWeightValue);
  }

  FWeightedValue.NullCheck = function (value) {
   if (value == null) {
    return 0.0;
   } else {
    return value;
   }
  }
  
  FWeightedValue();
 }
}


function fldStatus()
{ with ( crmForm.all )
 { if ( statuscode.SelectedText == 'Won' || statuscode.SelectedText == 'Lost' )
  { crmForm.SetFieldReqLevel("rg_winlossreason", 1);
   sectionDisplay( false, rg_winlossreason );
  }
  else
  { crmForm.SetFieldReqLevel("rg_winlossreason", 0);
   rg_winlossreason.DataValue = null;
   sectionDisplay( true, rg_winlossreason );
  }
 }
}

function fldGSMC()
{ with ( crmForm.all )
 { sectionDisplay( !rg_gsmc.DataValue, rg_contractnumber );
  crmForm.SetFieldReqLevel("rg_contracttype", ( rg_gsmc.DataValue ? 1 : 0 ));
 }
}

function fldMerge(fld)
{ if ( fld == null ) { return; }

 var cell = $(fld + '_d');
 if ( cell == null ) { return; }

 var row = cell.parentNode;
 if ( row == null ) { return; }

 cell.colSpan = 3;
 row.removeChild(cell.nextSibling);
 row.removeChild(cell.nextSibling);

}

function frmTabs()
{ tab('Hidden', 'hidden');
}

function frmNav()
{ navHide ('nav_rg_opportunity_rg_opportunitypracticearea');
 navHide ('nav_rg_opportunity_rg_opportunityservicearea');
 navHide ('nav_rg_opportunity_rg_engagementteam');
 navHide ('nav_rg_opportunity_rg_opportunityteam');

 navHide ('navProducts');
 navHide ('navQuotes');
 navHide ('navOrders');
 navHide ('navInvoices');
 navHide ('navComp');
 navHide ('_NA_SFA');}

function frmIFrames()
{ /* Engagement Team */
 var n2nPA = new N2NViewer('IFRAME_EngagementTeam'); 
 /* Set the role order - use iedevtoolber for exact parameters */  
 n2nPA.RoleOrder = 1; 
 /* assing the relationship name (without the "area" word) */  
 n2nPA.TabsetId  = "rg_opportunity_rg_engagementteam"; 
 n2nPA.Load(); 

 /* Opportunity Team */
 var n2nPA = new N2NViewer('IFRAME_OpportunityTeam'); 
 n2nPA.RoleOrder = 1; 
 n2nPA.TabsetId  = "rg_opportunity_rg_opportunityteam"; 
 n2nPA.Load(); 

 /* Practice Areas */
 var n2nPA = new N2NViewer('IFRAME_PracticeAreas'); 
 n2nPA.RoleOrder = 1; 
 n2nPA.TabsetId  = "rg_opportunity_rg_opportunitypracticearea"; 
 n2nPA.Load(); 

 /* Service Areas */
 var n2nService = new N2NViewer('IFRAME_Services'); 
 n2nService.RoleOrder = 1; 
 n2nService.TabsetId  = "rg_opportunity_rg_opportunityservicearea"; 
 n2nService.Load(); 
}

function $(name)
{ return document.getElementById(name);
}

function navHide (name)
{ if ($(name) != null) { $(name).style.display = "none"; }
}

function tab ( tabName, tabVisibility )
{ tabVisibility = ( tabVisibility == "visible" ? "" : "none" );

 var _tabs = crmForm.getElementsByTagName("li");
 for (var i = 0; i < _tabs.length; i++)
 { var _tab = _tabs[i];
  if ( _tab.innerText == tabName )
  { _tab.style.display = tabVisibility;
   break;
  }
 }
}

function sectionDisplay(vis, sec)
{ sec.parentElement.parentElement.parentElement.style.display = ((vis) ? 'none' : 'block');
}

function ResizeScreen()
{ var aH = screen.availHeight;
 var aW = screen.availWidth;
 var top = 0;
 var left = 0;

 if ( aW >= 1124 && aH >= 800)
 { var aH = (aH > 800 ? 800 : 768);
  var aW = 1124;
  var top = (screen.availHeight - aH) / 2;
  var left = (screen.availWidth - aW) / 2;
 }
// aH = (crmForm.FormType == frmType.Create ? 295 : aH);
 window.moveTo(left, top);
 window.resizeTo(aW, aH);
}

function N2NViewer(iframeId) 
{ if (!document.all[iframeId]) 
 { alert(iframeId + " is missing!"); 
  return; 
 }

 var viewer = this; 
 var _locAssocObj = null; 
  
 viewer.IFRAME = document.all[iframeId]; 
 viewer.RoleOrder; 
 viewer.TabsetId; 
  
 viewer.Load = function() 
 {   if (crmForm.ObjectId != null)
  { /* Construct a valid N2N IFRAME url */ 
   viewer.IFRAME.src = "areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=" + crmFormSubmit.crmFormSubmitSecurity.value + "&roleOrd="+ viewer.RoleOrder +  "&tabSet=" + viewer.TabsetId; 
   viewer.IFRAME.onreadystatechange = viewer.StateChanged; 
  }
  else
  { viewer.IFRAME.src = "about:blank"; 
  }
 }
 
 viewer.StateChanged = function() 
 { if (viewer.IFRAME.readyState != 'complete') 
  { return; 
  }
   
  var iframeDoc = viewer.IFRAME.contentWindow.document; 
   
  /* Reomve scrolling space */ 
  iframeDoc.body.scroll = "no"; 
  /* Remove crmGrid Default padding */ 
  iframeDoc.body.childNodes[0].rows[0].cells[0].style.padding = 0; 
   
  /* Save MS locAssocObj */ 
  _locAssocObj = locAssocObj; 
  /* Override MS locAssocObj */ 
  locAssocObj = viewer.locAssocObj; 
 } 
  
 viewer.locAssocObj = function(iType , sSubType, sAssociationName, iRoleOrdinal) 
 { /* Open the Dialog */ 
  _locAssocObj(iType , sSubType, sAssociationName, iRoleOrdinal); 
  /* Refresh only if our iframe contains the correnct tabset name */ 
  if (sAssociationName == viewer.TabsetId) 
  { viewer.IFRAME.contentWindow.document.all.crmGrid.Refresh();  
  }
 } 
}  


function AddLogoToFormTitle(logoWidth, logoUrl)
{ var formTitleTable = null;
 var tables = document.getElementsByTagName("table");

 for(var i = 0; i < tables.length; i++)
 { var className = tables[i].className;
  if (className && className.indexOf("ms-crm-Form-Title") == 0)
  { formTitleTable = tables[i];
   break;
  }
 }

 if (formTitleTable)
 { var newCell = formTitleTable.rows[0].insertCell(2);
  newCell.width = logoWidth;
  newCell.vAlign = "middle";
  newCell.innerHTML = '<img src="'+logoUrl+'" border="0" align="right" />';
 }
}

 

function UnUsed()
{
  if(false)
  {
    try
    {


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>