Task-8 : Updating Project Start Date and End Date

 Task-8 : Updating Project Start Date and End Date

User Story: -

On selection of asset in case entity, read the project in asset, project start date and end date from project entity, set the dates on case entity from as project start date and end dates.

Sudo code: -

  • Create a lookup field of Asset entity in Case entity.
  • Create two Date type fields as Project Start date and Project End date in Case entity.
  • Create a Project Entity.
    • In this Project entity create 2 fields as Project Start date and Project End date
  • Create a Project entity lookup in Assert entity.
  • Create JavaScript code for OnChange event of Assert lookup in the Case entity.
    • Retrieve the Assert lookup record Id from Case Entity.
    • By using REST Builder you can get the web API based code for retrieving the Project Start date and end date from Asset related entity.
    • Set the retrieved project start date and end date to Case entity project start date and end date fields using JavaScript methods.
  • Create a web resource using this completed JavaScript code.
  • Create an OnChange event for Assert field in Case entity using this JavaScript web resource.

Task procedure: -













JavaScript code to create web resource: -

function UpdateStartDateAndEndDates(executionContext) {
var formContext = executionContext.getFormContext();

var Asset = formContext.getAttribute("cr172_assert").getValue();

if(Asset != null){
var Assert_Id = Asset[0].id;

Xrm.WebApi.online.retrieveRecord("msdyn_customerasset", Assert_Id, "?$expand=cr172_Project($select=naree_enddate,naree_startdate)").then(
function success(result) {
var msdyn_customerassetid = result["msdyn_customerassetid"];
if (result.hasOwnProperty("cr172_Project")) {
var cr172_Project_naree_enddate = result["cr172_Project"]["naree_enddate"];
var cr172_Project_naree_startdate = result["cr172_Project"]["naree_startdate"];

formContext.getAttribute("cr172_startdate").setValue(new Date(cr172_Project_naree_startdate));
formContext.getAttribute("cr172_enddate").setValue(new Date(cr172_Project_naree_enddate));

}
},
function(error) {
Xrm.Navigation.openAlertDialog(error.message);
}
);
}
else {
formContext.getAttribute("cr172_startdate").setValue(null);
formContext.getAttribute("cr172_enddate").setValue(null);
}
}








Comments

Popular posts from this blog

Task -6 JavaScript , Regular expressions

Task_1 JavaScript