diff --git a/CAPS/CustomWorkflowActivities/CustomWorkflowActivities.csproj b/CAPS/CustomWorkflowActivities/CustomWorkflowActivities.csproj index 069e241..285137a 100644 --- a/CAPS/CustomWorkflowActivities/CustomWorkflowActivities.csproj +++ b/CAPS/CustomWorkflowActivities/CustomWorkflowActivities.csproj @@ -41,16 +41,16 @@ ..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll - ..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.52\lib\net462\Microsoft.Crm.Sdk.Proxy.dll + ..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.56\lib\net462\Microsoft.Crm.Sdk.Proxy.dll ..\packages\Microsoft.IdentityModel.7.0.0\lib\net35\microsoft.identitymodel.dll - ..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.52\lib\net462\Microsoft.Xrm.Sdk.dll + ..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.56\lib\net462\Microsoft.Xrm.Sdk.dll - ..\packages\Microsoft.CrmSdk.Workflow.9.0.2.52\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll + ..\packages\Microsoft.CrmSdk.Workflow.9.0.2.56\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll @@ -76,12 +76,18 @@ + + ..\packages\System.ServiceModel.Http.4.10.3\lib\net461\System.ServiceModel.Http.dll + + + ..\packages\System.ServiceModel.Primitives.4.10.3\lib\net461\System.ServiceModel.Primitives.dll + ..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll - - ..\packages\System.Text.Json.8.0.3\lib\net462\System.Text.Json.dll + + ..\packages\System.Text.Json.8.0.5\lib\net462\System.Text.Json.dll ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll diff --git a/CAPS/CustomWorkflowActivities/app.config b/CAPS/CustomWorkflowActivities/app.config index bd33dbd..be3c49b 100644 --- a/CAPS/CustomWorkflowActivities/app.config +++ b/CAPS/CustomWorkflowActivities/app.config @@ -8,7 +8,7 @@ - + diff --git a/CAPS/CustomWorkflowActivities/packages.config b/CAPS/CustomWorkflowActivities/packages.config index 237653a..a244c4b 100644 --- a/CAPS/CustomWorkflowActivities/packages.config +++ b/CAPS/CustomWorkflowActivities/packages.config @@ -1,15 +1,17 @@  - - + + + + - + \ No newline at end of file diff --git a/CAPS/WebResources/Scripts/FormHandler/caps_ChildCareFacility.Form.js b/CAPS/WebResources/Scripts/FormHandler/caps_ChildCareFacility.Form.js index 0fe7de5..3394274 100644 --- a/CAPS/WebResources/Scripts/FormHandler/caps_ChildCareFacility.Form.js +++ b/CAPS/WebResources/Scripts/FormHandler/caps_ChildCareFacility.Form.js @@ -6,6 +6,7 @@ CAPS.ChildCareFacility = CAPS.ChildCareFacility || {}; CAPS.ChildCareFacility.form_onload = function (executionContext) { var formContext = executionContext.getFormContext(); CAPS.ChildCareFacility.updateAddressFields(formContext); + CAPS.ChildCareFacility.UpdateActualProjectedEnrolment(executionContext); formContext.getAttribute("caps_sameaddressasschoolfacility").addOnChange(function () { CAPS.ChildCareFacility.updateAddressFields(formContext, true); @@ -89,4 +90,115 @@ CAPS.ChildCareFacility.updateAddressFields = function (formContext, forceClear = formContext.getAttribute("caps_streetaddress").setValue(null); formContext.getAttribute("caps_postalcode").setValue(null); } -}; \ No newline at end of file +}; + +CAPS.ChildCareFacility.UpdateActualProjectedEnrolment = function (executionContext) { + + var formContext = executionContext.getFormContext(); + var currentCCActualEnrolment = CAPS.ChildCareFacility.GetLookup("caps_currentchildcareactualenrolment", formContext); + if (currentCCActualEnrolment !== undefined) { + var options = "?$select=caps_capacityunder36months,caps_capacity30monthstoschoolage,caps_capacitypreschool,caps_capacitymultiage,caps_capacityschoolage,caps_capacitysasg"; + Xrm.WebApi.retrieveRecord("caps_childcareactualenrolment", CAPS.ChildCareFacility.RemoveCurlyBraces(currentCCActualEnrolment.id), options).then( + function success(result) { + var capacityUnder36Months = result.caps_capacityunder36months; + var capacity30MonthsToSchoolAge = result.caps_capacity30monthstoschoolage; + var capacityPreSchool = result.caps_capacitypreschool; + var capacityMultiAge = result.caps_capacitymultiage; + var capacitySchoolAge = result.caps_capacityschoolage; + var capacitySASG = result.caps_capacitysasg; + + formContext.getAttribute("caps_under36months_currentenrolment").setValue(capacityUnder36Months); + formContext.getAttribute("caps_30monthstoschoolage_currentenrolment").setValue(capacity30MonthsToSchoolAge); + formContext.getAttribute("caps_preschool_currentenrolment").setValue(capacityPreSchool); + formContext.getAttribute("caps_multiage_currentenrolment").setValue(capacityMultiAge); + formContext.getAttribute("caps_schoolage_currentenrolment").setValue(capacitySchoolAge); + formContext.getAttribute("caps_sasg_currentenrolment").setValue(capacitySASG); + + }, + function (error) { + console.log(error.message); + } + ); + } + else if (currentCCActualEnrolment === undefined) { + var recordId = formContext.data.entity.getId().replace("{", "").replace("}", ""); + Xrm.WebApi.retrieveMultipleRecords("edu_year", "?$filter=edu_type eq 757500001 and statuscode eq 1").then( + function retrieveCurrentYearSuccess(currentYearRecord) { + if (currentYearRecord == null || currentYearRecord.entities.length == 0) { + // Not Found for some reason + return; + } + // Get Current Enrolment Projection + // Statuscdoe = 714430001 - Current + // Projection Year matching that obtained from previous query + // Facility matching that of current record + var childCareEnrolmentProjectionOptions = "?$filter=statuscode eq 714430001 and _caps_childcarefacility_value eq '" + recordId + "' and _caps_schoolyear_value eq '" + currentYearRecord.entities[0].edu_yearid + "'"; + Xrm.WebApi.retrieveMultipleRecords("caps_childcareenrolmentprojection", childCareEnrolmentProjectionOptions).then( + function success(result) { + if (result == null || result.entities.length == 0) { + return; // Nothing to process + } + var hasChanges = false; + var enrolmentProjUnder36Months = result.entities[0].caps_under36months; + var enrolmentProj30MonthsToSchoolAge = result.entities[0].caps_monthstoschoolage; + var enrolmentProjePreSchool = result.entities[0].caps_preschool; + var enrolmentProjeMultiAge = result.entities[0].caps_multiage; + var enrolmentProjSchoolAge = result.entities[0].caps_schoolage; + var enrolmentProjSASG = result.entities[0].caps_schoolageonschoolgrounds; + if (enrolmentProjUnder36Months != null) { + + formContext.getAttribute("caps_under36months_currentenrolment").setValue(enrolmentProjUnder36Months); + hasChanges = true; + } + if (enrolmentProj30MonthsToSchoolAge !== null) { + formContext.getAttribute("caps_30monthstoschoolage_currentenrolment").setValue(enrolmentProj30MonthsToSchoolAge); + hasChanges = true; + } + if (enrolmentProjePreSchool !== null) { + formContext.getAttribute("caps_preschool_currentenrolment").setValue(enrolmentProjePreSchool); + hasChanges = true; + } + if (enrolmentProjeMultiAge !== null) { + formContext.getAttribute("caps_multiage_currentenrolment").setValue(enrolmentProjeMultiAge); + hasChanges = true; + } + if (enrolmentProjSchoolAge !== null) { + formContext.getAttribute("caps_schoolage_currentenrolment").setValue(enrolmentProjSchoolAge); + hasChanges = true; + } + if (enrolmentProjSASG !== null) { + formContext.getAttribute("caps_sasg_currentenrolment").setValue(enrolmentProjSASG); + hasChanges = true; + } + + if (hasChanges) { + formContext.data.entity.save(); // Save the record if there were changes made. + } + + // Should only have 1 record + return; + + }); + }); + } + +}; + +CAPS.ChildCareFacility.GetLookup = function (fieldName, formContext) { + var lookupFieldObject = formContext.data.entity.attributes.get(fieldName); + if (lookupFieldObject !== null && lookupFieldObject.getValue() !== null && lookupFieldObject.getValue()[0] !== null) { + var entityId = lookupFieldObject.getValue()[0].id; + var entityName = lookupFieldObject.getValue()[0].entityType; + var entityLabel = lookupFieldObject.getValue()[0].name; + var obj = { + id: entityId, + type: entityName, + value: entityLabel + }; + return obj; + } +}; + +CAPS.ChildCareFacility.RemoveCurlyBraces = function (str) { + return str.replace(/[{}]/g, ""); +} diff --git a/CAPS/WebResources/Scripts/FormHandler/caps_Project.Form.js b/CAPS/WebResources/Scripts/FormHandler/caps_Project.Form.js index ac8f8fd..72c5759 100644 --- a/CAPS/WebResources/Scripts/FormHandler/caps_Project.Form.js +++ b/CAPS/WebResources/Scripts/FormHandler/caps_Project.Form.js @@ -1313,6 +1313,7 @@ CAPS.Project.ToggleBUSReplacement = function (executionContext) { formContext.getAttribute("caps_bus").setRequiredLevel("required"); if (executionContext.getFormContext() != FORM_STATE.CREATE) { formContext.getControl("caps_currentkilometers").setVisible(true); + formContext.getAttribute("caps_currentkilometers").setRequiredLevel("required"); } } @@ -1321,6 +1322,8 @@ CAPS.Project.ToggleBUSReplacement = function (executionContext) { formContext.getControl("caps_bus").setVisible(false); formContext.getAttribute("caps_bus").setRequiredLevel("none"); formContext.getControl("caps_currentkilometers").setVisible(false); + formContext.getAttribute("caps_currentkilometers").setRequiredLevel("none"); + formContext.getAttribute("caps_currentkilometers").setValue(null); if (formContext.getAttribute("caps_bus").getValue() != null && executionContext.getFormContext() != FORM_STATE.READ_ONLY) { formContext.getAttribute("caps_bus").setValue(null); } @@ -2065,10 +2068,14 @@ CAPS.Project.ShowHideOnCCPRFSFields = function (executionContext) { formContext.getAttribute("caps_operatorname").setValue(null); formContext.getControl("caps_operatorleaseloi").setVisible(false); formContext.getAttribute("caps_operatorleaseloi").setValue(null); + formContext.getAttribute("caps_operatorname").setRequiredLevel("none"); + formContext.getAttribute("caps_operatorleaseloi").setRequiredLevel("none"); } else { formContext.getControl("caps_operatorname").setVisible(true); formContext.getControl("caps_operatorleaseloi").setVisible(true); + formContext.getAttribute("caps_operatorname").setRequiredLevel("required"); + formContext.getAttribute("caps_operatorleaseloi").setRequiredLevel("required"); } } diff --git a/CAPS/WebResources/Scripts/Ribbon/caps_ChildCareActualEnrolment.Ribbons.js b/CAPS/WebResources/Scripts/Ribbon/caps_ChildCareActualEnrolment.Ribbons.js index 9950301..180ea38 100644 --- a/CAPS/WebResources/Scripts/Ribbon/caps_ChildCareActualEnrolment.Ribbons.js +++ b/CAPS/WebResources/Scripts/Ribbon/caps_ChildCareActualEnrolment.Ribbons.js @@ -245,4 +245,5 @@ CAPS.ChildCareActualEnrolment.UnsubmitReport = function (primaryControl) { ); } }); + }; \ No newline at end of file