Topic: ‘Script and Code’

 

JavaScript Form Button – Dynamics CRM 4.0

Posted December 2nd, 2009 by Ben Kerford / No Comments

Putting a button at the top of a CRM form is not always the most efficient.  In some cases, multiple buttons are needed and subsequently need to be placed in locations throughout the form.  Below is standard JavaScript that can be placed onLoad of a form to create a button that is displayed in the form.  As you look through the script, you will see comments that will help you build your button and provide the function that you need.

/*In entity attributes, create a field (new_button) that is a type nvarchar*/
/*Add the attribute to the form, in the location where you would like your button to display.*/
/*In the onLoad events, copy and paste the script below.  Be sure to substitute the (new_button) field with the field that you have created. */
/*hides the free text field of the attribute*/

crmForm.all.new_button_d.style.visibility = ‘hidden’; 

/* Replaces the Attribute description with an image.  The image that is displayed in the script can be seen below. */
/* The button image can be changed by changing the extension. */
/* Also defined in the function are the button actions.  In this example we have given the button an “onclick” action.  OnClick, we are going to launch an alert that says “hello”. */

if (crmForm.all.new_button != null)
{
var field = crmForm.all.new_button_c;

var html = “<table border=’0′ cellspacing=’0′ cellpadding=’0′><tr><img width=’32′ height=’32′ style=’cursor:hand’ src=’/_imgs/ico_16_1039_associated.gif’ alt=’Click button’ onclick=’Button_OnClick()’ /></tr></table>”;

field.innerHTML = html;
}
Button_OnClick = function()
{

/*Instead of launching an alert, you could change the format of the form, create a SOAP function or launch a program.*/

alert(”hello”);
}

JavaScript Form Button

Continue Reading

 

Using Dynamics CRM 4.0 to Calculate ROI

Posted November 30th, 2009 by Kristen O'Connor / No Comments

I absolutely love using calculation javascript – it ends up being worth the time and effort it takes to place it inside of the system. It’s amazing to think about the total amount of time you save by utilizing this custom functionality. However, the most difficult part of generating a collection of calculation code is coming up with the actual formula and making sure it calculates out correctly.

I recently read a blog by Mitch Milam on the Microsoft CRM team blog that was completely inspiring. He has generated a simple collection of calculations that will generate a final ROI amount for you. While there’s no code on the actual blog, the calculation javascript is simple and well known. As long as you place Mitch’s concept behind the javascript, it should be relatively simple to piece together.

Click here to view Mitch’s calculation concept on the MS CRM team blog.

This concept is extremely powerful from a decision-making standpoint. Your return on investment can illustrate many things – are you spending the money you’re spending NOW in the right places? Are you going to be putting your money where the best return actually lies? These decisions cannot be made without viewing your ROI. And being able to plug in a few numbers and see the final piece to the puzzle is just fantastic.

Continue Reading

 

Field Concatenation Javascript in Dynamics CRM 4.0

Posted November 23rd, 2009 by Kristen O'Connor / No Comments

Concatenation can be a simple thing to do, as long as you know how to do it. I was having some trouble finding some concatenation code, so a colleague pointed me to this code last week. It allows me to concatenate four fields into one field:
 
crmForm.CONCATENATEDFIELD.DataValue = crmForm.FIELD1.DataValue + crmForm.FIELD2.DataValue + crmForm.FIELD3.DataValue + crmForm.FIELD4.DataValue
 
The structure of the code is pretty simplistic – the concatenated field would technically be “equal to” to the values of the other four fields. If you want to include more fields, simply add additional fields in the same format to the end of the existing string. Be sure to place the concatenation fields in the order you want it to be seen in the final field. 
 

Continue Reading

 

Adjustment of Prefixes in XML Causes Stripped Original Display Names in CRM 4.0

Posted April 14th, 2009 by Kristen O'Connor / No Comments

A few days ago, I tried for the first time adjusting the prefixes of custom attributes inside of an XML customizations file. I exported the XML file, found and replaced “new_” with “ibis_,” and tried to re-import the file. When I did, the Original Display Names of some entities in the system were missing. The section where the name would be displayed was merely blank. There wasn’t really a pattern (i.e. only Custom entities), so I enlisted the help of a colleague and began to inspect the XMl file for any kind of irregularities.

After around 20 minutes of searching through the XML file, we noticed something strange. In the XML file to the right of OriginalName, there were two quotation marks side by side ” ”, with no Original Display Name in between them:

one-4102009
This was odd – I hadn’t made this change to the XML file.

We decided that the stripped OriginalNames between the quotations had to be the culprit. We searched through the XML file, found all of the OriginalName sections that were blank, and replaced them with the exact name of each entity. After saving and reuploading the file, the Original Display Names were back up there.

If you have encountered the same issue yourself, follow these steps in order to fix the issue:

1. Open your XML file in NotePad.
2. Select the Find option, and make sure that your cursor is at the top of the document.
3. In the Find area, type in the name of the entity your are searching for. Click Next until you find the line in the code where LocalizedName and Original Display Name and together, and the quotation marks are side by side with nothing in between them.
4. Place the cursor in between the quotation marks and type in the exact Display Name of the entity.
5. Repeat steps 3 and 4 until you have found and inserted all of the missing display names.
6. Save, Close, and reupload the XML document into CRM.

Continue Reading

 

Extending the Limit of Form Tabs in CRM 4.0

Posted March 11th, 2009 by John Bowdler / No Comments

I recently was engaged with a client who was challenged with the limitation of 8 tabs per entity form in CRM 4.0. After several attempts to manage the requirements around the limitations of 8 tabs, I began doing some in depth research for a way to step beyond the boundaries. Not only did I find a solution, but it is a solution that does not require you to be a hard core coder like some. For those of you who are willing to make this change, it’s important to understand that this solution is not supported by Microsoft. However, it has been noted by Dynamics design team that there was no noteworthy reason to have the 8-tab limitation, but just as noteworthy that your unsupported change will indeed cause issues if you do not reduce your max tabs down to 8 before attempting an upgrade. Therefore, you will likely have to take the sections on tabs 9-x and temporarily move them (for the purposes of your upgrade) to tabs 1 – 8.

To maximize the number of tabs per entity form, navigate to the following location on the CRM server:

C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\Tools\FormEditor

1. Find the formeditor.aspx and right click on it and select “edit.”

2. Find the JavaScript variable “_iMaxTabs” and notice that it is set to 8. Change the value to your desired limitation, then save and close.

3. Lastly, reset IIS and you should then be able to create the additional tabs needed from within the forms customization area.

one-3112009

Continue Reading

 

Retrieve Fields from Related Entities to Populate Fields on a Form in Microsoft Dynamics CRMv4

Posted February 24th, 2009 by David Pritchett / 13 Comments

I have been working with a client that I had implemented last year and one of their original requirements was to populate fields on a form with values from fields already filled in on related entities. We all know that if two entities are related, as in Account and Contact, you can map fields from one to the other and the values will be transferred from the parent to the child if you create the child record under the parent record. However, what if you still want certain values to be inherited from other records no matter how you create the child record or if the relationship is not parent/child? For example, I want the Contact record to inherit values from the Account record I select in the Account lookup on the Contact form when I create a new Contact. This can be done by implementing some code via an onChange event on the Account lookup field. Since you need to actually send a query to retrieve these values, this requires some advanced java script techniques such as building an XML query, creating an Active X object and parsing the object to retrieve the values you need for your form. There are several examples on how to do this type of functionality floating around on various places on the web, but I always have a hard time finding them when I need to go back for reference, so I thought I would post a comprehensive example here. You can use this and apply it to any entity that is related to another entity. I will over-comment the code to explain what is going on, but you can remove later if you wish. This example will retrieve the Telephone and Owner fields from the Account and set them to the respective fields on the Contact.

/* ————————————————————————————————

Begin.

Retrieves the Telephone and Owner field values from the Account record

based on the Account selected

————————————————————————————————–*/

// Get the data value of the Account lookup after the Account is selected

var AccountLookUp = crmForm.all.parentcustomerid.DataValue;

if (AccountLookUp != null && AccountLookUp != “undefined”)

{

// Get the value for the accountid from the array and set it to a variable

var AccountID = AccountLookUp[0].id;

//alert(AccountID);

/*————————————————————————————————

Build your query XML that you will use to create the ActiveX object. This is using standard SDK protocol. In this example I just retrieve all of the fields from the Account. You can vary your query to only retrieve certain fields or to pass other parameters. Check with the SDK to see examples of how to build your query in this way. Here, I am just retrieving all Account fields based on the AccountID of the Account selected

————————————————————————————————–*/

var Accountxml = “” +

“<?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\”>” +

GenerateAuthenticationHeader() +

” <soap:Body>” +

” <RetrieveMultiple xmlns=\”http://schemas.microsoft.com/crm/2007/WebServices\”>” +

” <query xmlns:q1=\”http://schemas.microsoft.com/crm/2006/Query\” xsi:type=\”q1:QueryExpression\”>” +

” <q1:EntityName>account</q1:EntityName>” +

” <q1:ColumnSet xsi:type=\”q1:AllColumns\” />” +

” <q1:Distinct>false</q1:Distinct>” +

” <q1:Criteria>” +

” <q1:FilterOperator>And</q1:FilterOperator>” +

” <q1:Conditions>” +

” <q1:Condition>” +

” <q1:AttributeName>accountid</q1:AttributeName>” +

” <q1:Operator>Like</q1:Operator>” +

” <q1:Values>” +

” <q1:Value xsi:type=\”xsd:string\”>” + AccountID + “</q1:Value>” +

” </q1:Values>” +

” </q1:Condition>” +

” </q1:Conditions>” +

” </q1:Criteria>” +

” </query>” +

” </RetrieveMultiple>” +

” </soap:Body>” +

“</soap:Envelope>” +

“”;

//alert(Accountxml);

/*————————————————————————————————

Create the ActiveX object. Once again, this is standard protocol. Notice the

last two lines that pass our Query XML that we created above.

————————————————————————————————*/

var xmlHttpRequest = new ActiveXObject(”Msxml2.XMLHTTP”);

xmlHttpRequest.Open(”POST”, “/mscrmservices/2007/CrmService.asmx”, false);

xmlHttpRequest.setRequestHeader(”SOAPAction”,”http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple”);

xmlHttpRequest.setRequestHeader(”Content-Type”, “text/xml; charset=utf-8″);

xmlHttpRequest.setRequestHeader(”Content-Length”, Accountxml.length);

xmlHttpRequest.send(Accountxml);

// Set the XML response to a variable that can be parsed later.

var resultAccountXml = xmlHttpRequest.responseXML;

//alert(resultAccountXml);

/*————————————————————————————————

Create a container for the “nodes” retrieved. Essentially, these are just the

fields that are returned in the XML result.

————————————————————————————————*/

var entityNodes = resultAccountXml.selectNodes(”//RetrieveMultipleResult/BusinessEntities/BusinessEntity”);

// Loop through the collection of returned entities.

// Note that the query above limits the result to a single entity, so you will only find one

// node. To be more specific, it could be 0 nodes as well, if you don’t have access to accounts

// or your system is empty.

for (var i = 0; i < entityNodes.length; i++) {

// Access the current array element

var entityNode = entityNodes[i];

// Attributes are child nodes of the BusinessEntity node. Use selectSingleNode to return

// the first occurrence of a named node. The selectNodes method we used before returns all

// matching nodes, but as an attribute name only occurs once, selectSingleNode is easier to use.

// Use the same namespace alias (q1) you have specified in the query.

var TelephoneNode = entityNode.selectSingleNode(”q1:telephone1″);

var OwnerNode = entityNode.selectSingleNode(”q1:ownerid”);

// Always check for null values. If an attribute is set to null, it is not contained in the

// resulting XML. And accessing accountidNode.text when accountidNode is null leads to

// a runtime error.

var Telephone = (TelephoneNode == null) ? null : TelephoneNode.text;

var Owner = (OwnerNode == null) ? null : OwnerNode.text;

// alert(Telephone);

// alert(Owner);

}

// Set the values retrieved from the Account to the corresponding fields on your Contact form.

crmForm.all.telephone1.DataValue = Telephone;

crmForm.all.ownerid.DataValue = Owner;

}

/* ————————————————————————————————

End.

————————————————————————————————–*/

If you are not a hardcore code writer like me, then keep these things in mind when building your own code:

1) Most of the code above is standard, and you are simply plugging in variables along the way. So, follow the variables as they are created and see where they are plugged in.

2) The syntax for the Query XML, ActiveX Object and Node parsing is all standard protocol. There is no need to tweak this (although calling the web service could change over time and versions), except to pass your specific variables.

3) Debug using alert() along the way to track your variables and make sure they are being assigned properly. I left the ones I typically use in my example above.

Note: Certain parts of the code above have been copied from other sources and I left the whole comments intact. I would like to give credit to the original author(s), but I don’t know who they are. So, thanks to whoever posted the original examples!

Continue Reading

 

Issues with CRM 4.0 Client for Microsoft Outlook on Terminal Server: CRM Add-in Disabled

Posted January 26th, 2009 by Peter Bertell / No Comments


Symptoms
: The CRM 4.0 Client for Microsoft Outlook works when first configured for a user on a terminal server, but when the user logs off and logs back on, the CRM add-in for Outlook is disabled. The user then receive the following message:

WarningDiagnosticCheckException: You recently used a different Outlook profile than the one the Microsoft Dynamics CRM add-in has been configured for. The Microsoft Dynamics CRM add-in will be enabled only for the profile it was configured for. at Microsoft.Crm.Outlook.Diagnostics.

Background: The CRM 4.0 Client for Microsoft Outlook gets successfully installed to the terminal server by an administrator. An end user then logs in and successfully configures the client, and the CRM 4.0 Client for Microsoft Outlook performs as expected. Once the user logs off and logs back on, the CRM add-in for Outlook is disabled.

Cause: The server was configured with Login scripts that are clearing the outlook profile without checking a condition it is already there. Another login script is then running to configure Outlook for the user without any user input. The CRM 4.0 Client for Microsoft Outlook realizes this upon initialization and disables the CRM add-in for Outlook.

Solution: Be sure that your terminal server login scripts, or files, called by those login scripts are checking to see if the Outlook profile for the user that is logging in exists and does not remove and recreate a profile if one already exists.

Continue Reading