yes sure mohad,
1.Defining the columns to Grid
columnArray.push(
{
name: "scheduledstart",
type: "dateTime",
required: true,
editable: true,
title: "Planned Date",
width: "40px",
editor: DateTimeEditor
});
2.Binding Values to Grid
function DateTimeEditor(container, options) {
var fromdate;
var todate;
if (window.parent.Xrm.Page.getAttribute("pcl_fromdate").getValue() != null && window.parent.Xrm.Page.getAttribute("pcl_fromdate").getValue() != undefined) {
fromdate = window.parent.Xrm.Page.getAttribute("pcl_fromdate").getValue();
}
if (window.parent.Xrm.Page.getAttribute("pcl_todate").getValue() != null && window.parent.Xrm.Page.getAttribute("pcl_todate").getValue() != undefined) {
todate = window.parent.Xrm.Page.getAttribute("pcl_todate").getValue();
}
jQuery('<input data-text-field="formattedValue" data-value-field="value" data-bind="value:' + options.field + '"/>')
.appendTo(container).kendoDatePicker(
{
value: new Date(),
min: new Date(fromdate),
max: new Date(todate),
parseFormats: ["dd/MM/yyyy"]
}).data("kendoDateTimePicker");
}
3. Retrieving the Attributes from attributes from Appointment
function RetrieveRecords() {
debugger;
var isplan = false;
var travelPlanId = window.parent.Xrm.Page.data.entity.getId();
var id = travelPlanId.replace(/\{|\}/gi, '');
if (window.parent.Xrm.Page.getAttribute("pcl_travelplanstage").getValue() != null && window.parent.Xrm.Page.getAttribute("pcl_travelplanstage").getValue() != undefined) {
if (window.parent.Xrm.Page.getAttribute("pcl_travelplanstage").getValue() == 0) {
isplan = true;
}
else if (window.parent.Xrm.Page.getAttribute("pcl_travelplanstage").getValue() == 1) {
isplan = false;
}
}
if (travelPlanId != "") {
var data = [];
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/appointments?$select=activityid,pcl_expectedtime,pcl_isplaned,pcl_planedhour,pcl_dealertype,pcl_multipleactivities,pcl_travelplanactivitystatus,pcl_type,_pcl_typeofdealer_value,_regardingobjectid_value,scheduledend,scheduledstart,statecode,subject&$filter=_regardingobjectid_value eq " + id + "", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\",odata.maxpagesize=5000");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
Appresults = JSON.parse(this.response);
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
if (results.value[i].scheduledstart != null && results.value[i].scheduledstart != undefined) {
record.scheduledstart = results.value[i].scheduledstart.split("T")[0]; //results.value[i].scheduledstart;
}
4.updating/ Creating the Record
function updateRecord(EntityObj, entityobjectid) {
if (window.parent.Xrm.Page.getAttribute("pcl_travelplanstage").getValue() != null && window.parent.Xrm.Page.getAttribute("pcl_travelplanstage").getValue() != undefined) {
if (window.parent.Xrm.Page.getAttribute("pcl_travelplanstage").getValue() == 0) {
isplan = true;
}
else if (window.parent.Xrm.Page.getAttribute("pcl_travelplanstage").getValue() == 1) {
isplan = false;
}
}
if (isplan == true) {
if (EntityObj.data.scheduledstart != null && EntityObj.data.scheduledstart != undefined) {
var start = new Date(EntityObj.data.scheduledstart);
startdate = new Date(start.getFullYear(), start.getMonth(), start.getDate(), parseInt(data[0]), parseInt(data[1]), 0, 0);
if (EntityObj.data.pcl_planedhour != null && EntityObj.data.pcl_planedhour != undefined) {
updateRecord.attributes["pcl_planedhour"] = {
formattedValue: EntityObj.data.pcl_planedhour.formattedValue,
value: EntityObj.data.pcl_planedhour.value,
type: 'OptionSetValue'
}
enddate = new Date(start.getFullYear(), start.getMonth(), start.getDate(), parseInt(data[0]) + parseInt(EntityObj.data.pcl_planedhour.formattedValue), parseInt(data[1]), 0, 0);
}
updateRecord.attributes["scheduledstart"] = startdate;
updateRecord.attributes["scheduledend"] = enddate;
}
}
Can you please help on this
Regards
Shankar