8. 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
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
1. Create a custom entity with the name of
Project
·
Provide start date and date fields with
date time datatype
2.
In Customer asset entity, provide a
project entity lookup with the name of project
3.
In case entity
·
Provide a customer asset entity lookup
with the name of Asset
·
Provide a start date and end date fields
with data time datatype
4.
From CRM Rest builder, retrieve code to
read a guid of asset record from asset lookup
5.
From CRM Rest builder, retrieve code to read
project start date and end date from project lookup
6.
Write a JavaScript function to display
start date and end date in case entity and place it in web resource
·
If asset lookup not equal to null
i.
Read project record guid with the help
of rest builder code using asset guid
¨
If
Project record is not equal to null
i.
Read the project start date and end date
with the help of CRM rest builder using project guid
v Set start
date and end date to asset in case entity.
7.
Call JavaScript function from Asset
field on change in case entity
Create a custom entity with the name of Project
·
Provide start date and date fields with date time datatype
In Customer asset entity, provide a project entity lookup with the
name of project
In case entity
·
Provide a customer asset entity lookup with the name of Asset
·
Provide a start date and end date fields with data time
datatype
From CRM Rest builder, retrieve code to read a guid of asset record
from asset lookup
Xrm.WebApi.online.retrieveRecord("msdyn_customerasset",
"00000000-0000-0000-0000-000000000000",
"?$select=_new_project_value").then(
function success(result) {
var _new_project_value =
result["_new_project_value"];
var _new_project_value_formatted =
result["_new_project_value@OData.Community.Display.V1.FormattedValue"];
var
_new_project_value_lookuplogicalname =
result["_new_project_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
From CRM Rest builder, retrieve code to read project start date and
end date from project lookup
Xrm.WebApi.online.retrieveRecord("effi_project",
"00000000-0000-0000-0000-000000000000",
"?$select=effi_enddate,effi_startdate").then(
function success(result) {
var effi_enddate =
result["effi_enddate"];
var effi_startdate =
result["effi_startdate"];
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
Write a JavaScript function to display start date and end date in
case entity
function assetProject(executionContext)
{
var
formContext = executionContext.getFormContext();
var asset =
formContext.getAttribute("new_asset").getValue();
if (asset
!= null && asset != undefined)
{
var name =
asset[0].name;
var id =
asset[0].id.replace("{", "").replace("}", "");
Xrm.WebApi.online.retrieveRecord("msdyn_customerasset", id, "?$select=_new_project_value").then(
function success(result)
{
var projectId = result["_new_project_value"];
var _new_project_value_formatted = result["_new_project_value@OData.Community.Display.V1.FormattedValue"];
var _new_project_value_lookuplogicalname = result["_new_project_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
if (projectId != null
&& projectId != undefined)
{
Xrm.WebApi.online.retrieveRecord("effi_project", projectId , "?$select=effi_enddate,effi_startdate").then(
function success(result)
{
var effi_startdate = result["effi_startdate"];
var effi_enddate = result["effi_enddate"];
// to convert date format
var startDate = new Date(effi_startdate);
var endDate = new Date(effi_enddate);
// new_projectenddate new_projectstartdate
formContext.getAttribute("new_projectstartdate").setValue(startDate);
formContext.getAttribute("new_projectenddate").setValue(endDate);
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
}
Call JavaScript function from Asset field on change in case entity
Output:
Comments
Post a Comment