function saveRecord(context) {
var rec = context.currentRecord;
try{
var startDate = rec.getValue({
fieldId: "custbody_clb_periodstartingdate",
});
log.debug("startDate=",startDate);
var endDate = rec.getValue({
fieldId: "custbody_clb_periodendingdate",
});
log.audit("startDate", startDate + "endDate" + endDate);
/* startDate = new Date(('0' + (startDate.getMonth() + 1)).slice(-2) + '/'
+ ('0' + startDate.getDate()).slice(-2) + '/'
+ startDate.getFullYear());
endDate = new Date(('0' + (endDate.getMonth() + 1)).slice(-2) + '/'
+ ('0' + endDate.getDate()).slice(-2) + '/'
+ endDate.getFullYear());*/
/* startDate = format.parse({
value: startDate,
type: format.Type.DATE
});
endDate = format.parse({
value: endDate,
type: format.Type.DATE
});*/
if(NullCheck(startDate)&&NullCheck(endDate)){
var lineCount = rec.getLineCount({
sublistId: "time",
});
log.audit(
"line Count",
lineCount +
"startDate" +
startDate.getTime() +
"endDate" +
endDate.getTime()
);
for (var t = 0; t < lineCount; t++) {
var apply = rec.getSublistValue({
sublistId: "time",
fieldId: "apply",
line: t,
});
// log.audit("apply",apply)
if (apply == true) {
var date = rec.getSublistValue({
sublistId: "time",
fieldId: "billeddate",
line: t,
});
/*date = format.parse({
value: date,
type: format.Type.DATE
});*/
log.audit("fdate", new Date(date) + "date less tha" + date.getTime());
log.audit(
"Less Than",
Number(date.getTime()) <= Number(endDate.getTime())
);
log.audit(
"Greater Than",
Number(date.getTime()) >= Number(startDate.getTime())
);
// if((date <= endDate) && (date >= startDate)){1673424000000 1674115200000 1673942400000
if (
Number(date.getTime()) >= Number(startDate.getTime()) &&
Number(date.getTime()) <= Number(endDate.getTime())
) {
log.audit("Into");
} else {
alert("Selected Billable Time's Date is Out off Service Period.Please apply only within period Billable Times");
return false;
// var myCustomError = error1.create({
// name: "OUT_OFF_DATES",
// message: "Selected Dates Are Out off Service Period.",
// notifyOff: true,
// });
// log.error("Error: " + myCustomError.name, myCustomError.message);
// throw myCustomError;
}
}
}
}
}
catch (e){
log.error("error in saveRecord",e)
}
return true;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter