function getEmployeeCounts(executionContext) { var formContext = executionContext.getFormContext(); var formType = GetFormType(formContext); if (formType == 2) {// execute only if formType == Update var company = formContext.getAttribute("digins_companyid").getValue(); //Get RFP's Company if (company[0] != null) { var guid = company[0].id; var entType = company[0].entityType; try { //Get Number of Employees and Employees (Benefit Eligible) from Company Xrm.WebApi.retrieveRecord(entType, guid, "?$select=name,numberofemployees,digins_employeesbenefiteligible") .then(function (data) { setEmployeesForRFPAndSegmentSize(formContext, data); }, function (error) { Xrm.Utility.alertDialog(error.message); }); } catch (e) { Xrm.Utility.alertDialog(e.message); } } }
<pre>function getEmployeeCounts(executionContext) { var formContext = executionContext.getFormContext(); var formType = GetFormType(formContext); if (formType == 2) {// execute only if formType == Update var company = formContext.getAttribute("digins_companyid").getValue(); //Get RFP's Company if (company[0] != null) { var guid = company[0].id; var entType = company[0].entityType; try { //Get Number of Employees and Employees (Benefit Eligible) from Company Xrm.WebApi.retrieveRecord(entType, guid, "?$select=name,numberofemployees,digins_employeesbenefiteligible") .then(function (data) { setEmployeesForRFPAndSegmentSize(formContext, data); }, function (error) { Xrm.Utility.alertDialog(error.message); }); } catch (e) { Xrm.Utility.alertDialog(e.message); } } } } function setEmployeesForRFPAndSegmentSize(formContext, data) { //digins_segmentsize options // 2-99 (867460000) // 100-249 (867460001) // 250-499 (867460002) // 500-999 (867460003) // 1000+ (100000000) //Get Get Employees (Benefit Eligible) value (which is optional) var employeesbenefiteligible = data.digins_employeesbenefiteligible; //Get Number of Employees (which is required) var numberofemployees = data.numberofemployees; // Use employeesbenefiteligible if populated otherwise use numberofemployees var employeeCountToEvaluate = employeesbenefiteligible ?? numberofemployees; //Get Employees for RFP var employeesForRFP = formContext.getAttribute("digins_employeesforrfp").getValue(); //Determine if Employees for RFP is null if (employeesForRFP == null) { //Set employeesForRFP to employee count from company formContext.getAttribute("digins_employeesforrfp").setValue(employeeCountToEvaluate); } else { //Use Existing Employees For RFP employeeCountToEvaluate = employeesForRFP; } //Get SegmentSize control, value. and text var segmentSizeControl = formContext.getAttribute("digins_segmentsize"); var currentSegmentSizeValue = segmentSizeControl.getValue(); var currentSegmentSizeText = segmentSizeControl.getText(); var newSegmentSizeText = ""; var newSegmentSizeValue; //Determine Segment size for RFP based on Client's Employees (Benefit Eligible) value OR numberofemployees switch (true) { case (employeeCountToEvaluate < 100): newSegmentSizeText = '2-99'; newSegmentSizeValue = 867460000; segmentSizeControl.setValue(867460000); break; case (employeeCountToEvaluate < 250): newSegmentSizeText = '100-249'; newSegmentSizeValue = 867460001; segmentSizeControl.setValue(867460001); break; case (employeeCountToEvaluate < 500): newSegmentSizeText = '250-499'; newSegmentSizeValue = 867460002; segmentSizeControl.setValue(867460002); break; case (employeeCountToEvaluate < 1000): newSegmentSizeText = '500-999'; newSegmentSizeValue = 867460003; segmentSizeControl.setValue(867460003); break; case (employeeCountToEvaluate >= 1000): newSegmentSizeText = '1000+'; newSegmentSizeValue = 100000000; segmentSizeControl.setValue(100000000); break; default: alert('employeeCountToEvaluate is out of range'); break; } } //Determine if the RFP's current Segment Size Value is other than suggested based on the number of employees TOOK OUT DUE TO AUTOMATION 9/19/2023 /*if (currentSegmentSizeValue != newSegmentSizeValue) { setSegmentSizeConfirmation(segmentSizeControl, currentSegmentSizeText, newSegmentSizeText, newSegmentSizeValue); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)