Notifications
Announcements
Hi ,
I am looking JS code for calculate end date (from start date & No.of Days ).I have archive through JS but need to skip weekends.
function Count_Date(executionContext){var formContext = executionContext.getFormContext();var Approved=formContext.getAttribute("cre9e_approved").getValue();var Days=formContext.getAttribute("cre9e_noofdays").getValue();if (Days != null && Approved == 859640000) {var startdate = formContext.getAttribute("cre9e_startdate").getValue();var enddate = new Date();enddate.setTime(startdate.getTime() + (Days * 24 * 60 * 60 * 1000));formContext.getAttribute("cre9e_enddate").setValue(enddate );
}}
is there any way to skip weekends after providing No of days
Hi zahid.tectree,
Please refer to this post in the Stack Overflow:
stackoverflow.com/.../add-no-of-days-in-a-date-to-get-next-dateexcluding-weekends
Hi,
can u please provide a code because i have try many ways to archive but not working (its working in vs code & other).if there is any other way to archive please let me know want to archive (skip weekend as well as holidays).
Thanks
Please try the following code:
function onLoad(executionContext){ var formContext = executionContext.getFormContext(); // Get value var startDate= formContext.getAttribute("cr2f9_startdate").getValue(); var Days=formContext.getAttribute("cr2f9_noofdays").getValue(); //holidays array var holidays = [new Date("2021/12/24").getTime()]; if(startDate != null && Days != null){ var endDate = "",count = 0; while (count < Days){ endDate = new Date(startDate.setDate(startDate.getDate() 1)); if(endDate.getDay() != 0 && endDate.getDay() != 6 && !holidays.includes(endDate.getTime())){ count ; } } formContext.getAttribute("cr2f9_enddate").setValue(endDate); } }
Result:
Its work but I want to get holiday dynamically .
scenario I have a custom entity name holidays where i have added some holidays. wants to get that holiday .
is there any way ...........
You could use retrieveMultipleRecords() method to get all records in your custom entity and then add the holiday date to the holiday array.
could you please provide more information
Please refer to this blog to use retrieveMultipleRecords() method: https://carldesouza.com/retrieve-and-retrievemultiple-javascript-using-xrm-webapi/
If you are still stuck, please provide the columns in your custom entity and I would provide the code to do this on Monday.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Tom_Gioielli 24 Super User 2025 Season 2
TAHER Mehdi 14
Fameeda Yaseen 10