Skip to main content

Using MS CRM Calendar in your custom ASP .NET pages *** Not fully Supported Customisations ***

Hi,
Have you been creating custom pages in line with MS CRM for creating , viewing and updating entity records ? Have you placed controls such as Date picker Lookup on your custom page and have tried in vein to make those look like MS CRM ?

I found a way to use the same MS CRM calendar control as it appears in the application...



For getting this calendar on your asp .net page, follow the steps below:


1) Create a copy of the date.js javascript file located in your-server/crmsite-folder/_static/_controls/datetime folder, give the copy some name like date_myapp.js.

2) Open the following .js files from different sub folders in side the your-server/crmsite-folder/_static
     folder :

  •       Global.js
  •       encodedecode.js
  •       xmlutil.js
  •       util.js
  •       remotecommand.js             
Copy and whole content of each file one by one and keep pasting the same to the end of your date_myapp.js file.

3) Now open any CRM entity record page, for example a new Account create page, view its source and copy all the constant declaration lines :

or, copy the lines as below and paste to the very beginning of your date_myapp.js file
//-----------------------------------------------------------------------------------------


var LOCID_SELECTBOX_BUTTON_ALT = "Display list of options";
var LOCID_CLOSE_BUTTON_LABEL = "Close";
var LOCID_POPUP_MENU_LABEL = "\x7b0\x7d Menu";
var LOCID_DEVERROR_BADTYPE_STRING = "This control only accepts strings or null as an input.";
var LOCID_DEVERROR_TOO_LONG = "The text entered exceeds the maximum length.";
var LOCID_LU_SELECT_VALUE_FOR = "Click to select a value for \x7b0\x7d.";
var LOCID_LU_SELECT_VALUE = "Click to select a value.";
var LOCID_LU_ERROR_RESOLVED = "There was an error while trying to resolve the typed in text. Please use the lookup dialog to set the value.";
var LOCID_LU_MSG_HASUNRESOLVEDITEMS = "The Lookup could not be resolved to a record in the system. You must select the record for the system to use before you can save.";
var LOCID_LU_LOOKUPUNRESOLVEDTOOLTIP = "No matches were found";
var LOCID_LU_LOOKUPAMBIGUOUSTOOLTIP = "More than one match was found";
var LOCID_DEVERROR_BADTYPE_PICKLIST = "This control only accepts strings, integers, or null as an input.";
var LOCID_DATE_SELECT_DATE = "Select date";
var LOCID_BOOL_SUPPORTED_VALUES = "This control only supports true, false, or null as an input.";
var LOCID_EXCEEDED_MAX_CHARS_MASK = "You have exceeded the maximum number of \x7b0\x7d characters in this field\x3b it will be truncated.";
var LOCID_LOADING_NOTES_DATA = "Loading...";
var LOCID_NOTEAREA_TITLE = "Note";
var LOCID_FORM_REQUIRED_BKG_COLOR = "";
var LOCID_FORM_REQUIRED_ALT = "Required";
var LOCID_COPY_SHORTCUT_ERROR = "The shortcut could not be copied to the clipboard.";
var LOCID_UI_DIR = "LTR";
var LOCID_AM_DESIGNATOR = "AM";
var LOCID_PM_DESIGNATOR = "PM";
var LOCID_FIRST_WEEK_SELECT = "FirstDay";
var LOCID_NO_SELECTION = "You must select at least one time slot from the calendar.";
var LOCID_TREE_PLUS = "Collapsed, click to expand";
var LOCID_TREE_MINUS = "Expanded, click to collapse";
var LOCID_RELATEDINFO_DATALOADING = "Loading...";
var LOCID_RELATEDINFO_NORESULTS = "No results found.";
var LOCID_RELATEDINFO_FLWUP_OK = "Successfully created \x7b0\x7d \x7b1\x7d";
var LOCID_RELATEDINFO_FLWUP_SUBJ = "Follow Up\x3a \x7b0\x7d";
var LOCID_RELATEDINFO_EXPAND = "Click to open Form Assistant \x28CTRL-SHIFT-F\x29";
var LOCID_RELATEDINFO_COLLAPSE = "Click to close Form Assistant \x28CTRL-SHIFT-F\x29";
var LOCID_RELATEDINFO_ENDSTARTERR = "You must specify an end time that happens after the start time.";
var LOCID_RELATEDINFO_TASKNOTREGOBJ = "Quick Campaigns cannot have Task as a Follow up activity";
var LOCID_UNRECOGNIZE_DOTC = "\x7b0\x7d is not a recognized Object type.";
var LOCID_XML_PROCESS_ERROR = "There was an error processing your request. Please wait and try again later.";
var LOCID_POPUP_BLOCKER_ERROR = "A Microsoft Dynamics CRM window was unable to open, and may have been blocked by a pop-up blocker. Please add this Microsoft Dynamics CRM server to the list of sites your pop-up blocker allows to open new windows\x3a";
var LOCID_BU_CANNOTDISABLE = "It has been detected that this operation would deactivate all remaining business units and cannot proceed.";
var LOCID_DIALOG_OFFSET_WIDTH = "0";
var LOCID_DIALOG_OFFSET_HEIGHT = "0";
var LOCID_ERROR_DIALOG_WIDTH = "550";
var LOCID_ERROR_DIALOG_HEIGHT = "260";
var LOCID_CONTRACTS_TDIALOG_WIDTH = "350";
var LOCID_CONTRACTS_TDIALOG_HEIGHT = "350";
var LOCID_MAX_RECORDS_ERROR = "The maximum number of records that can be selected for this action is 10.";
var LOCID_ERROR_INVALID_VIEW = "Shortcut for the selected view is not available.";
var LOCID_ARRAY_SHORT_MONTHS = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,";
var LOCID_ARRAY_LONG_MONTHS = "January,February,March,April,May,June,July,August,September,October,November,December,";
var LOCID_ARRAY_SHORT_DAYS = "Sun,Mon,Tue,Wed,Thu,Fri,Sat";
var LOCID_ARRAY_SHORTEST_DAYS = "Su,Mo,Tu,We,Th,Fr,Sa";
var LOCID_ARRAY_LONG_DAYS = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday";
var LOCID_SHOW_WEEK_CAL_WIDTH = "170";
var LOCID_NO_WEEK_CAL_WIDTH = "150";
var LOCID_CALENDAR_HEIGHT = "163";
var LOCID_TODAY_DATE_FORMAT_MASK = "Today\x3a \x7b0\x7d";
var LOCID_ALERT_ENTER_VALID_DATE = "The specified date format is invalid or the date is out of valid range. Enter a valid date in the format\x3a \x7b0\x7d";
var LOCID_ALERT_CALDATE_FAIL = "An error has happened in getting the date";
var LOCID_ALERT_ACTUAL_DATE_FAIL = "An error has happened getting the date";
var LOCID_YEAR_DISPLAYFORMAT = "\x7b0\x7d\x7b1\x7d";
var LOCID_SINGULAR_MINUTE = "minute";
var LOCID_PLURAL_MINUTE = "minutes";
var LOCID_SINGULAR_HOUR = "hour";
var LOCID_PLURAL_HOUR = "hours";
var LOCID_SINGULAR_DAY = "day";
var LOCID_PLURAL_DAY = "days";
var LOCID_VALID_DURATION = "You must enter a valid duration.";
var LOCID_ERROR_SAVE_DURATION = "Microsoft Dynamics CRM was unable to save the change to duration.  Try changing the duration value again.";
var LOCID_1_MINUTE = "1 minute";
var LOCID_5_MINUTES = "5 minutes";
var LOCID_15_MINUTES = "15 minutes";
var LOCID_30_MINUTES = "30 minutes";
var LOCID_45_MINUTES = "45 minutes";
var LOCID_1_HOUR = "1 hour";
var LOCID_1_5_HOURS = "1.5 hours";
var LOCID_2_HOURS = "2 hours";
var LOCID_2_5_HOURS = "2.5 hours";
var LOCID_3_HOURS = "3 hours";
var LOCID_3_5_HOURS = "3.5 hours";
var LOCID_4_HOURS = "4 hours";
var LOCID_4_5_HOURS = "4.5 hours";
var LOCID_5_HOURS = "5 hours";
var LOCID_5_5_HOURS = "5.5 hours";
var LOCID_6_HOURS = "6 hours";
var LOCID_6_5_HOURS = "6.5 hours";
var LOCID_7_HOURS = "7 hours";
var LOCID_7_5_HOURS = "7.5 hours";
var LOCID_8_HOURS = "8 hours";
var LOCID_1_DAY = "1 day";
var LOCID_2_DAYS = "2 days";
var LOCID_3_DAYS = "3 days";
var LOCID_DURATION_BADTYPE = "This control only accepts integers between \x7b0\x7d and \x7b1\x7d or null as input.";
var LOCID_DURATION_NOSAVE = "Microsoft Dynamics CRM was unable to save the change to duration.  Try changing the duration value again.";
var LOCID_ONE_MINUTE_MASK = "\x7b0\x7d minute";
var LOCID_N_MINUTES_MASK = "\x7b0\x7d minutes";
var LOCID_1_HOUR_MASK = "\x7b0\x7d hour";
var LOCID_N_HOURS_MASK = "\x7b0\x7d hours";
var LOCID_1_DAY_MASK = "\x7b0\x7d day";
var LOCID_N_DAYS_MASK = "\x7b0\x7d days";
var LOCID_DTM_BLANK_DATE_ERROR = "You must provide a date.";
var LOCID_DTM_BLANK_TIME_ERROR = "Enter a valid time.";
var LOCID_TIME_SEPARATOR = "\x3a";
var LOCID_LCID = "1033";
var LOCID_DATEPATTERN = "\x5e\x5cd\x5cd\x3f.\x5cd\x5cd\x3f.\x5cd\x5cd\x5cd\x5cd\x5cd\x3f";
var LOCID_FORMS_SAVE_CONFIRM_TITLE = "Your changes have not been saved. To stay on the page so that you can save your changes, click Cancel.";
var LOCID_FORM_PROIVE_VALUE_MASK = "You must provide a value for \x7b0\x7d.";
var LOCID_FORM_PRINT_DIRTY_MESSAGE = "This form has been changed and must be saved before printing.";
var LOCID_PLEASE_ENTER_SEARCH = "Please enter search criteria.";
var LOCID_NO_ASTERISK = "The search field cannot contain the asterisk \x28\x2a\x29 character.  Remove any that are used and try again.";
var LOCID_NO_FULL_TEXT_SEARCH_OFFLIN = "This type of search is unavailable while Outlook is offline.  Try browsing by subject or go online.";
var LOCID_LOOKUPSTYLE_NOT_SET = "Unknown lookup style. Check that your properties XML is set properly.";
var LOCID_LOOKMORERECORDS_AMBIGUOUS = "Look Up More Records";
var LOCID_LOOKUPAMBIGUOUSTITLE = "More than one match was found\x3a";
var LOCID_ENTER_VALID_NUMBER = "You must enter a valid number.";
var LOCID_SCHEDDLG_RSQUANTITYALL = "All";
var LOCID_SCHEDDLG_RSLEASTBUSY = "Least Busy";
var LOCID_SCHEDDLG_RSMOSTBUSY = "Most Busy";
var LOCID_SCHEDDLG_RSSITESAME = "The same site";
var LOCID_SCHEDDLG_RSSITEANY = "Any site";
var LOCID_SCHEDDLG_RSCUSTOM = "Custom";
var LOCID_SCHEDDLG_DISABLED_RES = "\x7b0\x7d \x28Disabled\x29";
var LOCID_SCHEDDLG_FMTNMCS = "Choose \x7b0\x7d \x28\x7b1\x7d\x29 From \x7b2\x7d";
var LOCID_SCHEDDLG_FMTNM_S = "Choose \x7b0\x7d From \x7b2\x7d";
var LOCID_SCHEDDLG_FMTNMC_ = "Choose \x7b0\x7d \x28\x7b1\x7d\x29";
var LOCID_SCHEDDLG_FMTNM__ = "Choose \x7b0\x7d";
var LOCID_REMOTECOMMAND_ERROR = "An error has occurred. Try this action again. If the problem continues, check the Microsoft Dynamics CRM Community for solutions or contact your organization\x27s Microsoft Dynamics CRM Administrator. Finally, you can contact Microsoft Support.";

var WEB_APP_URL = "";
var HELP_SKU = "OP";
var IS_LIVE = false;
var IS_PATHBASEDURLS = true;
var ORG_UNIQUE_NAME = "contoso";
var _ErrorCodesIsvAborted = "0x80040265";
var ScriptErrorReportingPreference = 1;
var ScriptErrorStatusBar = "Error on page.";
var _bPresenceEnabled = true;
var ORG_DATE_FORMATSTRING = "M\x2fd\x2fyyyy";
var ORG_IS_GREGORIANCALENDAR = false;
var ORG_DATE_SEPARATOR = "\x2f";
var ORG_DATE_START_DAY = 0;
var ORG_LANGUAGE_CODE = 1033;
var ORG_NUMBER_FORMAT_MASK = "\x23,\x23\x230.\x2a\x3b\x7e\x23,\x23\x230.\x2a";
var ORG_TIME_FORMAT = 0;
var ORG_SHOW_WEEK_NUMBER = false;
var ORG_NUMBER_DECIMAL_SEPARATOR = ".";
var ORG_NUMBER_GROUP_SEPARATOR = ",";
var SERVER_URL = "http\x3a\x2f\x2fcrmdev\x2fcontoso";
var AUTHENTICATION_TYPE = 0;
var CRM2007_WEBSERVICE_NS = "http\x3a\x2f\x2fschemas.microsoft.com\x2fcrm\x2f2007\x2fWebServices";
var CRM2007_CORETYPES_NS = "http\x3a\x2f\x2fschemas.microsoft.com\x2fcrm\x2f2007\x2fCoreTypes";
var ORG_TIMEZONE_OFFSET = 60;
var USER_DATE_FORMATSTRING = "M\x2fd\x2fyyyy";
var USER_IS_GREGORIANCALENDAR = true;
var USER_DATE_SEPARATOR = "\x2f";
var USER_DATE_FORMATTED_FORMATSTRING = "M\x2fd\x2fyyyy";
var DEFAULT_USER_NUMBER_FORMAT_MASK = "\x23,\x23\x230.\x2a\x3b\x7e\x23,\x23\x230.\x2a";
var USER_LANGUAGE_CODE = 1033;
var USER_HELP_LCID = "1033";
var USER_NUMBER_FORMAT_MASK = "\x23,\x23\x230.\x2a\x3b\x7e\x23,\x23\x230.\x2a";
var USER_TIME_FORMAT = "h\x3amm tt";
var USER_SHOW_WEEK_NUMBER = false;
var USER_NUMBER_DECIMAL_SEPARATOR = ".";
var USER_NUMBER_GROUP_SEPARATOR = ",";
var HELP_SERVER_URL = "";
//-----------------------------------------------------------------------------------------------------

4) Out of these lines, observer the 2 variables : ORG_UNIQUE_NAME and SERVER_URL , and you can see in the above case, the organisation name is contoso you will have to hard code the values of these 2 variables by your organisation name.



5)  Find this line in the entire date_myapp.js
  

       <  Something >   = LocalDateTimeNow();
and replace the function call ,
         <  Something >   =  new Date(); //LocalDateTimeNow(); 


PS : Just a little note on common sense, while searching just search "LocalDateTimeNow();" 


6)  
         search for this line or a part of it in your date related javascript file : date_.js
             var sCommandNamespace = _sWebServicesNamespace;
         comment this line and add this line ;
            var sCommandNamespace = "http://schemas.microsoft.com/crm/2006/WebServices"; //_sWebServicesNamespace;

7)  Also ,you may get another error related to _awrpc token not found, let me know if that happens, if so, simply go to your js file, search 
     1) function SetCrmWrpcToken(sUrl, sToken, sTimestamp) {
         and comment whole of tihs function's contents,
     2)  in this function :
        function GetCrmWrpcToken(sUrl) {
        add return null; as the first line of this function body.
8) 

  Now Add a Textbox and an Image in your application, 
   Write the following javascript function onclick of the image. 

function showCRMCalendar() {     
                  InitCalendar("M/d/yyyy", "/", 0, null, null);             LaunchCalendar(document.getElementById('TextBox1'), new Date(), 1, false, null, null, 1, new Date());        
 }

 9) 

       One final note on security context, your custom file , default.aspx or mypage.html must be           in ISV folder and must be accessed with the notion :  http://crmserver/isv/folder/default.aspx      

and that's it, you will see the same MSCRM style calendar in your app !!

YOU HAVE MORE REASON TO BE HAPPY THAT WE HAVE ADDED THE SOURCE CODE NOW, FIND HERE AT : 

Get MSCRM Calendar in your custom application

Comments

Anonymous said…
Hi, nice job, but i can not make it work.can u help me please? may u please supply your complete js file and your test page please so i can learn from them? if u are so kind to send, please send to paolo AT entity-ag DOT it
thx
hero said…
here is the file

http://cid-c81486946b1556f9.office.live.com/self.aspx/.Public/date20.js
Anonymous said…
thank you so much!!! i really appreciate. i just still dont understand some things.I set in the InitCalendar the format d/M/yyyy but i still see M/d/yyyy format.
and how can i set the day in calendar same as the date in textbox1?i mean after i set a date, i'd like that when i reopen the calendar its position its on the date selected..
any ideas? again, thank you very much
hero said…
o yes that script is in the aspx page i have posted that on the site as well, lemme paste it here as well, i ll do that in few hours
Anonymous said…
Thank you, i will wait for the script.by the way, u also solved the problem about date format?very strange that i use d/M/yyyy but still see M/d/yyyy.. anyway, thank you for all your help!!!!
Anonymous said…
Thank you, i will wait for the script.by the way, u also solved the problem about date format?very strange that i use d/M/yyyy but still see M/d/yyyy.. anyway, thank you for all your help!!!!
Anonymous said…
Hi!Sorry if i bother u.did u find solution for the format of the date? and how do i put back the calendar on the day its written on the textbox?
thank you!
hero said…
Hi Anonymous, Please find the js to write ms crm calendar value to textbox:

call this function on focus or click of the textbox

function launchCal()
{
// here is where you set the format InitCalendar("M/d/yyyy","/",0,null, null);
LaunchCalendar(document.getElementById('txtDate'), new Date(), 1, false, null, null, 1, new Date() );
}
Anonymous said…
Please put a working project so, we can have a look thanks
hero said…
dont u think thats asking for too much, i think i have already given the script and code when to call it, can you not make it work yet ?
Anonymous said…
Hi mate,
Thanks for your reply. First of all i must say you have done a great job here.
I have this error when i call the javascript function on my asp.net page. It says "Object expected". I am new to this and would greatly appreciate if you could help me out.
Thank you.
hero said…
Hi Anonymous, I understand your issue with javascript, must be some missing reference, do you mind doing a remote desktop session where we can work together and i can show you where the error could be ?

btw you can reach me on solutions.insystech@gmail.com
Anonymous said…
Thanks mate. I wouldn't be able to have a remote desktop session with you since it violates my company policy. But I could write the lines i have changed in your code plus lines i have added to my asp.net page.

var ORG_UNIQUE_NAME = "babilon";
var SERVER_URL = "http\x3a\x2f\x2flocalhost:5023";

ImageButton1.Attributes.Add("onClick", "javascript:LaunchCalendar(document.getElementById('TextBox1'), new Date(), 1, false, null, null, 1, new Date());");

Note: There are nine variables to be passed with javascript LaunchCalendar function. But you have only passed 8 values. Is on of the varibles is optional? By the way error triggers at the above asp.net (C#) code instance.

Thank you in advance for your help.
hero said…
Hi Anonymous,
I would suggest putting a debugger in your script, also, if you have used the js file i had posted, then it has a debugger as well or you can put extra debugger statements in that file and check the flow of statements.
Carlene said…
Nice blog. We are using small business CRMin our office, yet I'm not that knowledgeable regarding the technical stuff. Thanks for providing such blog. I really admire a CRM program, because it enables me set up appointments easy.
Anonymous said…
DataTime webservice is not returning any value .So I am Getting error "An error has happened in getting the date" .whether I am any config things here
Anonymous said…
DataTime webservice is not returning any value .So I am Getting error "An error has happened in getting the date" .whether I am any config things here
hero said…
Hi Anonymous, mail me on solutions.insystech@gmail.com and we shall sort ur issue
Anonymous said…
Hi Hero,

This is great stuff. I have a requirement in CRM for a custom entity's datetime field. I need to limit the date that can be picked to be less than 4 weeks from current date. i.e, dates prior to 4 weeks from current date should be disabled in the calendar. Can this even be done in CRM. Any help is greatly appreciated. Thanks !!

Raj.
hero said…
Hi Raj,
that's very simple, on the on change evnet of the date field just check the date against today's date and show an alert if its not within 4 weeks of the current date.
Srikanth Reddy said…
Hi mate,

Thanks for your great solution.I am also getting the same problem as Anonymous.
I have this error when i call the javascript function on my asp.net page. It says "Object expected".





function showCRMCalendar(id) {

try {
InitCalendar("M/d/yyyy", "/", 0, null, null);
LaunchCalendar(document.getElementById(id), new Date(), 1, false, null, null, 1, new Date());
}
catch (err) {
alert(err.message);
}
}

Note: There are nine variables to be passed with javascript LaunchCalendar function. But you have only passed 8 values

Thanks
hero said…
Hello Srikanth,
It's been really long since I moved from the project in which I used this script.

Could you email me a simple html page where you tried to implement this, a page that I can directly put in my ISV folder and test.

Or else give me a few days and I will create this at my end.

my email is shahsaurinb@gmail.com
Srikanth said…
Hi,

It's working fine, thanks for your response!
Dean Terry said…
Hi,

I'm trying to get the CRM date picker to launch from within a HTML webresource which is embedded on a form.
I've taken extracts of your code and have managed to get the control to popup, well it attempts to. All I can see is the top bar which displays the month and year and the two arrows.

Any ideas what may cause that and also have you ever tried to do this with any success?

Thanks,

Dean

Popular posts from this blog

Cancel Workflow job programmatically - CRM v.4

How many times you had to created a workflow on some date like Due date which keeps changing as per client's request. While this may sound simple in business, on CRM you have a workflow that may be waiting till this date and send a reminder exactly a week before. So you need to keep calling this workflow every time the date is updated, to make the matters more complicated, all the previous jobs that had initiated due to past modification will keep running and chasing that date which is never going to occur. What you do now, manually cancel those to save system resources and stop the never ending system jobs. There is a way to do it through SDK, in my case I call this function as a custom workflow activity in the first step of the workflow which Cancels any previous jobs of this workflow.   #region Cancel My WFs             QueryExpression qe = new QueryExpression();             qe.EntityName = EntityName.asyncoperation.ToString();             ColumnSet cs = new

Microsoft reuse windows media player toolbar in Windows 7

Those who have been using Windows Media Player would have experienced one thing over time, when you click on the little up-down arrow heads on the right, you could see a thumbnail live view of the current movie you were playing. This had been since Window XP and now Microsoft have copy-pasted this code to show live preview of each taskbar window like a folder, browser session, office documents and every possible item you can open and appear in task bar.  Those of you who haven't seen Windows 7, this is how taskbar preview looks like :