Notifications
Announcements
No record found.
Hi Everyone,
I am very new to Dynamics365 sales and also to this forum. Please be kind if this seems a very basic question to you
So my requirement is to extract the week number when an opportunity was modified. I already have a field 'Modified On' but couldn’t find ways to calculate the week number from the date. Any help is appreciated.
Many Thanks,
Manisha
Hi Manisha,
You can create a custom field whose field type is calculated.
And set the calculation as:
Then you’ll see the result.
Thank you so much for your response. However, I think I didn't phrase the question properly. I am looking to get the week number when the opportunity was last modified not the duration in weeks. So, for example, if I modify an opportunity today i.e modified date 20-July-2021 it should show 'Week 29', for date 26-July-2021 it should be 'Week 30' so on.
Thanks,
Hey Manisha Choudhary!
With the knowledge I have, I would suggest you use a Javascript function that triggers whenever the field 'Modified On' is changed. (Not sure if this is the best approach for your requirement)
Here is the function:
Date.prototype.getWeek = function() { var date = new Date(this.getTime()); date.setHours(0, 0, 0, 0); // Thursday in current week decides the year. date.setDate(date.getDate() 3 - (date.getDay() 6) % 7); // January 4 is always in week 1. var week1 = new Date(date.getFullYear(), 0, 4); // Adjust to Thursday in week 1 and count number of weeks from date to week1. return 1 Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 (week1.getDay() 6) % 7) / 7); } function CalcWeekNumber (executionContext) { const formContext = executionContext.getFormContext(); const modifiedDate = new Date(formContext.getAttribute('modifiedon').getValue()); const weekNumber = modifiedDate.getWeek(); formContext.getAttribute('weekNumberField').setValue(weekNumber); }
Source of the function
This function will set the ISO week number of the Modified on date to a new field you need to create. Make sure to change 'modifiedon' and 'weekNumberField' for the schema name of your field.
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 170 Super User 2025 Season 2
#ManoVerse 70
Jimmy Passeti 50 Most Valuable Professional