Neil McDonald's Dynamics CRM Blog

Posts Tagged ‘javascript

Chrome 37 breaks CRM 2011 and 2013 functionality

with 20 comments

Google has removed a number of APIs from Chrome 37 which is causing a lot of issues with CRM 2011 and CRM 2013. So far I’ve noticed: –

  • You can no longer add options to Option Set fields via customisation
  • Changes made to an email in a workflow are not saved when the save button is clicked
  • The ‘Upload’ button on the SharePoint list component no longer works
  • Anything using the ‘window.showModalDialog’ function no longer works as the API has been deprecated
  • Can no longer save field properties such as ‘Visible by default’
  • Export to Excel no longer works

In order to fix the problem until Microsoft issue a real fix, you can re-enable the deprecated features by following the below: – Read the rest of this entry »

Written by neilmcd

September 8, 2014 at 1:35 pm

Posted in CRM 2011, Misc

Tagged with , ,

Cross Browser Support For Calling Workflow Via Ribbon Buttons

with 2 comments

For some time now, I’ve been using ribbon buttons to call various workflows, both from open records and subgrids. There’s a good guide here on how to do this, but like most guides, they were written before update rollup 12 was released. Since cross-browser support was introduced in UR12, I’ve found that the ribbon buttons do not work unless I’m using Internet Explorer.

After looking at the JavaScript code again, I could see why it was failing (snippet below)

var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
Xrm.Page.context.getAuthenticationHeader() +
"<soap:Body>" +
"<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"<Request xsi:type=\"ExecuteWorkflowRequest\">" +
"<EntityId>" + guid + "</EntityId>" + //entity record ID
"<WorkflowId>" + workflowId + "</WorkflowId>" + //WorkflowId - guid of the workflow
"</Request>" +
"</Execute>" +
"</soap:Body>" +
"</soap:Envelope>";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.send(xml);

The XMLHttpRequest is being created using ActiveX, which is only supported by Internet Explorer.

Simply changing the affected code to the below has fixed the issue and it now works across all browsers.

var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("POST", "/mscrmservices/2007/CrmService.asmx", false);

Note: The change on the second line may not be obvious, but .open has been changed to use a lower case O

Written by neilmcd

March 27, 2013 at 5:17 pm

Add a CRM Calendar to a dashboard

with 9 comments

Dashboards in Dynamics CRM 2011 are a great way to visualize data. Did you know that they can also be used to view pretty much any other web content?

I’ve recently had a requirement to add the CRM Calendar to a dashboard. I could have simply added a list of appointment activities to the dashboard, but the actual calendar control looks a lot nicer.

To do this, first we need to get the URL of the Calendar page. Load up the IE developer tools (F12 in IE9) and start a profiler. Now navigate to the calendar in CRM and click on ‘Month’, ‘Week’ and ‘Day’ (we want the URL for each page).

1_cycle_through_pages

Stop the profiler and take a look at the results

2_profiler

As you can see, we’ve got the URLs of the 3 calendar views needed for the dashboard. The URL seems to contain a parameter for the current date in ISO8601 format (YYYY-MM-DDThh:mm:ss). We’ll have to deal with that inside of our web resource.

Read the rest of this entry »

Written by neilmcd

May 10, 2011 at 4:00 pm

Posted in CRM 2011

Tagged with , , ,

Set age based on date of birth

with one comment

Dob_js

I had a requirement to set an ‘Age’ attribute based on the contents of the Date of Birth field on Contacts. The below script in the On Save, On Load or On Change will do this.

Note: You will need to change the “birthdate” and “new_age” field names to the relavant fields on your form.

CRM 2011


function calcBirthday() {
if(Xrm.Page.getAttribute("birthdate").getValue() != null)
{
var now = new Date(); //get today's date
var birthday = Xrm.Page.getAttribute("birthdate").getValue(); //get the dob value
var diff = now.getMonth() - birthday.getMonth();  //have they had their birthday already this year?
var age; //use to store age

if (diff == 0) //if birthday is this month, compare the days instead
{
diff = now.getDate() - birthday.getDate();
}

if(diff > -1) //if they've had a birthday this year
{
age = now.getFullYear() - birthday.getFullYear();
}
else //if they have not had a birthday yet this year
{
age = now.getFullYear() - birthday.getFullYear() - 1;
}

Xrm.Page.getAttribute("new_age").setValue(age.toString()); //set the new_age attribute
}
}

CRM 4


function calcBirthday(){
if(crmForm.all.birthdate.DataValue != null)
{
var now = new Date(); //get today's date
var birthday = crmForm.all.birthdate.DataValue; //get the dob value
var diff = now.getMonth() - birthday.getMonth();  //have they had their birthday already this year?
if (diff == 0) //if birthday is this month, compare the days instead
{
diff = now.getDate() - birthday.getDate();
}

if(diff > -1) //if they've had a birthday this year
{
var bd1 = now.getFullYear() - birthday.getFullYear();
crmForm.all.new_age.DataValue =bd1.toString(); //set the new_age attribute
}
else //if they have not had a birthday yet this year
{
var bd2 = now.getFullYear() - birthday.getFullYear() - 1;
crmForm.all.new_age.DataValue =bd2.toString();
}
}
}

Written by neilmcd

July 16, 2010 at 11:07 am

Posted in CRM 2011, CRM 4

Tagged with ,

IE8 crashing when using picklists in Advanced Finds

leave a comment »

I’ve been having an issue where IE8 would crash when trying to use picklists in advanced finds (see below example).

It may not be a common issue, but I posted it on the MS partner forums and got the below response which has fixed it for me, so hopefully it will help someone else out too!

Edit AdvFind.aspx and add the following code. AdvFind.aspx can be found in the CRM web directoryAdvancedFind

NOTE: The code needs to be added right below function window.onload(){

<% if (Request.Params["AutoRun"] != "False")
{
%>
if (location.href.indexOf("?") > 0)
location.href = location.href + "&AutoRun=False";
else
location.href = location.href + "?AutoRun=False";
<%
}
%>

Written by neilmcd

July 14, 2010 at 10:05 am

View originating lead notes on a contact

leave a comment »

Our sales guys wanted a way to view originating lead notes against the Contacts created from Leads. I added a new tab to the contact containing an Iframe and used the below javascript to display the notes from the originating lead.


var lookupItem = new Array;
//set the lookup to the originating lead
lookupItem = crmForm.originatingleadid.DataValue;

if (lookupItem != null)
{
//display the originating lead notes in the iframe 'IFRAME_LeadNotes'
crmForm.all.IFRAME_LeadNotes.src="/_controls/notes/notesdata.aspx?id="+  lookupItem[0].id +  "&ParentEntity=3&EnableInlineEdit=false&EnableInsert=false";
}
else
{
//if there is no originating lead, hide the tab
crmForm.all.IFRAME_LeadNotes.src="about:blank";
tab7Tab.style.display = "none";
}

Written by neilmcd

July 9, 2010 at 10:38 am

Posted in CRM 4

Tagged with , , ,