Hey I need to know how can i do the validity duration and set it automatically as the alculated duration between Valid From and Valid To (in hours and in days) using JavaScript..
*This post is locked for comments
Mark the answer verified if it answers your question
Thank you Saad
If you want to set duration days and hours in same field then this filed should be Single Line of text. Use this script:
function DateDiff() {
var start = Xrm.Page.getAttribute('validfrom').getValue();
var end = Xrm.Page.getAttribute('validto').getValue();
// to cancel the error when undefined
if (start == undefined || start == null || end == undefined || end == null) {
return;
}
// Get 1 hour
var hour = 1000 * 60 * 60;
// Get time in hours
var hours = ((end - start) / hour);
// get Time in days
var daysToSet = Math.floor(hours/24);
// Get hours to set
var hoursToSet = hours % 24;
// Can't be less than 0.
if (daysToSet < 0)
daysToSet = 0;
if (hoursToSet < 0)
hoursToSet = 0;
var duration = daysToSet.toString() + " " + hoursToSet.toString();
// Set the duration
Xrm.Page.getAttribute('duration').setValue(duration);
}
I have in my form 2 fields : Valid to & Valid from, I need to calculate the Validity duration using java script; For example the time consumed doing a task
Please elborate what you want to achieve with an example. Unable to understand validity duration
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,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156