I am trying to validate the database records based on Start and End date of newly created record to check the overlapping of dates and to show the message if its is overlapping and further it has to allow to save the record on confirmation.
I was able to do this check for database records, but how can i check this within newly created rows whether the dates are been overlapping or not.
Here is my code:
var $ = skuid.$,
params = arguments[0],
list = params.list,
item = params.item,
model = params.model;
//var $ = skuid.$;
var save1 = false;
$(function(){
salescallM = skuid.model.getModel('SalesCallModel');
var rowIdsThatChanged = Object.keys(skuid.model.getModel(‘SalesCallModel’).changes);
var currentscRow = salescallM.getFirstRow();
var newstartdt = currentscRow.Start__c;
var newdt = new Date(skuid.time.parseSFDateTime(newstartdt).setMinutes(skuid.time.parseSFDateTime(newstartdt).getMinutes() + currentscRow.Duration_in_Minutes__c));
var newEndDt = skuid.time.getSFDateTime(newdt);
var newDurinMin = currentscRow.Duration_in_Minutes__c;
var owner = currentscRow.OwnerId;
console.log('NEWDur:'+ newDurinMin+ ' NStdt :'+ newstartdt+ ' NEndt:'+newEndDt);
var result = '';
//Database level overlap check
salescall = skuid.model.getModel('SalesCall');
var condition1 = salescall.getConditionByName('Start__c');
salescall.setCondition(condition1, newstartdt);
salescall.activateCondition(condition1);
var condition2 = salescall.getConditionByName('Calculated_End__c');
salescall.setCondition(condition2, newstartdt);
salescall.activateCondition(condition2);
var condition3 = salescall.getConditionByName('Start__c1');
salescall.setCondition(condition3, newstartdt);
salescall.activateCondition(condition3);
var pageTitle = $('#SalesCallRecs');
var editor = pageTitle.data('object').editor;
//if (rowIdsThatChanged = ‘’ ) //No changes made on row - to avoid saving on click of save without doing any action
if(rowIdsThatChanged.length > 0 && rowIdsThatChanged != ‘’)
{
$.each(salescall.getRows(),function(){
var startdt = this.Start__c;
var enddt = this.Calculated_End__c;
var name = this.Name;
if((startdt >= newstartdt && (startdt <= newEndDt && startdt < newEndDt)) || ((enddt >= newstartdt && enddt > newstartdt) && enddt <= newEndDt) ||(startdt <= newstartdt && enddt >= newEndDt))
{
save1 = true;
}
});
if(save1 == true)
{
result = confirm(“Sales Call exists with the same time slot. Do you still want to continue?”);
/editor.handleMessages(.{
message: ‘WARNING: Sales Call exists with the same time slot. Click Save to Continue’,
severity: ‘WARNING’
},]);/
if(result == true)
{
salescallM.save();
}
else if(result == false)
{
salescallM.cancel();
}
}
if(save1 == false) //to handle delete rows
{
salescallM.save();
}
}
});