Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

TypeError: bd.getWeek is not a function

(0) ShareShare
ReportReport
Posted on by 135

Hi All,

This javascript for week number was working fine with CRM 2013 but after migrating it with the XRMToolbox / Javamigrator to Dynamics 365 Sales I get the error "TypeError: bd.getWeek is not a function"
at weeknummer. Your help is much appreciated. Thank You.

function weeknummer(ExecutionContext){
/**
* Returns the week number for this date. dowOffset is the day of week the week
* "starts" on for your locale - it can be from 0 to 6. If dowOffset is 1 (Monday),
* the week returned is the ISO 8601 week number.
* @param int dowOffset
* @return int
*/
Date.prototype.getWeek = function (dowOffset) {
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.meanfreepath.com */

dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 1; //default dowOffset to zero
var newYear = new Date(this.getFullYear(),0,1);
var day = newYear.getDay() - dowOffset; //the day of week the year begins on
day = (day >= 0 ? day : day + 7);
var daynum = Math.floor((this.getTime() - newYear.getTime() -
(this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
var weeknum;
//if the year starts before the middle of a week
if(day < 4) {
weeknum = Math.floor((daynum+day-1)/7) + 1;
if(weeknum > 52) {
nYear = new Date(this.getFullYear() + 1,0,1);
nday = nYear.getDay() - dowOffset;
nday = nday >= 0 ? nday : nday + 7;
/*if the next year starts before the middle of
the week, it is week #1 of that year*/
weeknum = nday < 4 ? 1 : 53;
}
}
else {
weeknum = Math.floor((daynum+day-1)/7);
}
return weeknum;
}

if (ExecutionContext.getFormContext().getAttribute("new_prikdatum").getValue() != null)
{
var bd = ExecutionContext.getFormContext().getAttribute("new_prikdatum").getValue();

ExecutionContext.getFormContext().getAttribute("new_weeknummer").setValue(bd.getWeek());
ExecutionContext.getFormContext().getAttribute("new_weeknummer").setSubmitMode("always");
}
else
{
ExecutionContext.getFormContext().getAttribute(" new_weeknummer").setValue(null);
ExecutionContext.getFormContext().getAttribute(" new_weeknummer").setSubmitMode("always");
}
this.jaarweeknummer();
this.prikdatumtekst();
}

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.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans