If you click on “OK”, it will truncate your JavaScript. The good news that you can still create new webresource or update existing resources using some external text editor and upload that file into your JavaScript webresource.
Thanks.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Client; using Microsoft.Xrm.Client.Services; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messages; namespace dateCheck { class dateCheck { static void Main(string[] args) { //Date to be checked DateTime dateBeingTested = DateTime.Now; if (IsItWeekend(dateBeingTested) || CheckHolidays(dateBeingTested)) { Console.WriteLine(dateBeingTested.ToString("d") + " is not working day."); } else { Console.WriteLine(dateBeingTested.ToString("d") + " is a working day."); } } static bool IsItWeekend(DateTime date) { if ((date.DayOfWeek== DayOfWeek.Saturday) || (date.DayOfWeek==DayOfWeek.Sunday)) { return true; } return false; } static bool CheckHolidays(DateTime date) { var connection = new CrmConnection("Crm"); var service = new OrganizationService(connection); QueryExpression query = new QueryExpression("calendar"); query.ColumnSet = new ColumnSet(true); ConditionExpression condition = new ConditionExpression(); condition.AttributeName = "name"; condition.Operator = ConditionOperator.Equal; condition.Values.Add("Business Closure Calendar"); query.Criteria.Conditions.Add(condition); EntityCollection calendars = service.RetrieveMultiple(query); EntityCollection calendarrule = calendars[0].GetAttributeValue<EntityCollection>("calendarrules"); return calendarrule.Entities .Where(e => ((DateTime)e["starttime"]).Date == date.Date).Any(); } } }
<?xml version="1.0"?> <configuration> <connectionStrings> <!--<add name="Crm" connectionString="ServiceUri=http://servername/orgname; Domain=domainname; Username=username; Password=password"/>--> <add name="Crm" connectionString="ServiceUri=https://orgname.crm5.dynamics.com; Username=username; Password=password; DeviceID=deviceid; DevicePassword=password"/> </connectionStrings> </configuration>
<HTML><HEAD><TITLE></TITLE> <SCRIPT src="http://servername/SandpitAmreek//WebResources/new_/jquery1.7.2.js"></SCRIPT> <SCRIPT type=text/javascript> function callTheJsonp() { //debugger; // the url of the script where we send the asynchronous call //var url = "http://openexchangerates.org/api/latest.json?callback=?"; jQuery.getJSON("https://api.twitter.com/1/statuses/user_timeline.json?callback=?", { include_entities: "true", include_rts: "true", screen_name: "edwardsdna" }, function(data) { alert(data[0].text); }); } } </SCRIPT> <META charset=utf-8></HEAD> <BODY onload=callTheJsonp() contentEditable=true>hey hey</BODY></HTML>
<HTML><HEAD><TITLE></TITLE> <SCRIPT src="http://auntmsftv23/SandpitAmreek/WebResources/new_/jquery1.7.2.js"></SCRIPT> <SCRIPT type=text/javascript> function callTheJsonp() { debugger; // the url of the script where we send the asynchronous call var url = "http://openexchangerates.org/api/latest.json?callback=parseRequest"; $.ajax({ url: url, dataType: "jsonp", jsonpCallback: "parseRequest" }); } // this function should parse responses.. you can do anything you need.. // you can make it general so it would parse all the responses the page receives based on a data field function parseRequest(data) { try // try to output this to the javascript console { alert("AUD: " + data.rates.AUD);} catch(an_exception) // alert for the users that don't have a javascript console { alert(data); } } </SCRIPT> <META charset=utf-8></HEAD> <BODY onload=callTheJsonp() contentEditable=true>Testing Cross Domain Calls</BODY></HTML>
<HTML><HEAD><TITLE></TITLE> <SCRIPT src="https://crm5org01a03.crm5.dynamics.com//WebResources/new_/jquery1.7.2.js"></SCRIPT> <SCRIPT type=text/javascript> function callExchangeRate() { //debugger; jQuery.support.cors = true; var myurl = "http://openexchangerates.org/api/latest.json"; $.ajax({ type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: myurl, beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { // Use for a single selected entity alert(data.rates.AUD); // this line will display the exchange rate of AUD aganst USD }, error: function (xmlHttpRequest, textStatus, errorThrown) { alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown); } }); } </SCRIPT> <META charset=utf-8></HEAD> <BODY onload=callExchangeRate() contentEditable=true>Testing Cross Domain Calls</BODY></HTML>
<HTML><HEAD><TITLE></TITLE> <SCRIPT type=text/javascript> function callTheJsonp() { //debugger; // the url of the script where we send the asynchronous call var url = "http://openexchangerates.org/api/latest.json?callback=parseRequest"; // create a new script element var script = document.createElement('script'); // set the src attribute to that url script.setAttribute('src', url); // insert the script in out page document.getElementsByTagName('head')[0].appendChild(script); } // this function should parse responses.. you can do anything you need.. // you can make it general so it would parse all the responses the page receives based on a response field function parseRequest(data) { try // try to output this to the javascript console { alert("AUD: " + data.rates.AUD); } catch(an_exception) // alert for the users that don't have a javascript console { alert(data); } } </SCRIPT> <META charset=utf-8></HEAD> <BODY onload=callTheJsonp() contentEditable=true>Testing Cross Domain Calls</BODY></HTML>
I have named this web resource “new_/ColoredHeaderRed.css”. Here is the code.
.ms-crm-Form-HeaderContainer{ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#FF0000, endColorstr=#fff6f8faE); }
I have named this web resource “new_/ColoredHeaderGreen.css”. Here is the code.
.ms-crm-Form-HeaderContainer{ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#008000, endColorstr=#fff6f8faE); }
I have named this web resource “new_/ColoredHeaderScript.js”. The code is using a switch statement to attach an appropriate CSS file to the form, based on the value of customertypecode field. I am not using default in my switch statement as I don’t want to create a CSS file for default colour. Here is a code.
function loadCSS() { // get the value picklist field var relType = Xrm.Page.getAttribute("customertypecode").getValue(); var filename; switch (relType) { case 1: filename="/WebResources/new_/ColoredHeaderRed.css"; attachCSS(filename); break; case 2: filename="/WebResources/new_/ColoredHeaderGreen.css"; attachCSS(filename); break; } }// end function function attachCSS(filename){ var fileref = document.createElement("link"); fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", filename); document.getElementsByTagName("head")[0].appendChild(fileref); }Now call the loadCSS() function on account form load event.