Wednesday, May 26, 2010

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

Tuesday, May 18, 2010

Change Section name at runtime using Javascript

How many times you wanted to show/hide fields based on some load/save/change event in CRM and you did that with ease. Now I wonder you would have thought of changing the name of a Section as well that appears with a separator bar on top of each block of fields.

In order to do that, here is a sample code :

     crmForm.all..parentElement.parentElement.parentElement.children[0].childNodes[0].innerText="Your text";