Dear Experts,
am using Kendo Api for binding the values to the grid here my problem is am getting proper value in grid(am storing those values in appointment entity) in appointment entity am getting wrong date like it is showing previous date of selected date,
please can any one help me
This is my Function
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");
}
regards
shankar
*This post is locked for comments
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
Share the code where you are storing the date in CRM from datepicker.
From date and to dates are two date pickers from the parent record based on from date and to date am able to filter the date values in the grid date picker
What values are your getting in fromdate and todate variables
Thank you for your Responce Mohd Saad Akhtar,
i have already selected time Zone still am getting same Values
regards
shankar
Since you are writing client side code i suggest you to set the timezone to your timezone or of the server using Options of the user:
tutorial.programming4.us/.../Microsoft-Dynamics-CRM-2011---Setting-Personal-Options.aspx
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156