Conditional Lookup on Primary Contact of an Account

Tuesday, February 19th, 2008

This Post is based on a Post from AdvantageWorks in which a Filtered Lookup between 2 Lookups is described. Hessel Miedema and I created a Version of the Lookup for the Primary Contact of an Account. We used the Account Name as input for the Search Box of the Lookup of the Primary Contact. (Be aware that your Account Names need to be Unique in this Case).

The main Reason for this Post is that we noticed that the “&” character is Not allowed in a URL Request, but is allowed as Search Value. The “&” character needs to be replaced by “%26″ to function properly. A list of characters can be found in the The extended ASCII table .

The example we used on the OnLoad of the Account:

crmForm.all.primarycontactid.additionalparams = 'search=' + crmForm.all.name.DataValue.replace("&","%26").replace("+","%2b");

Improving GUI (static) information on forms

Wednesday, January 16th, 2008

In MS CRM most of the data is stored in regular changeable text boxes. For data that needs to be changed often this is useful. For data that hardly changes the boxes take up a lot of valuable space on the form. When we thought of this we came to the conclusion that it would be nice to have the information shown on the form as regular text, with the ability to change it in the regular way. The information takes a lot less space of the form. The space that is left can be used to show other information.
We have come up with a solution as shown below. The solution is not finished yet. The lay-out can be improved, but more important some of the links are lost, because they are shown as plain text. I’m working on these improvements.
The first picture shows a filled account form. I have used the standard account form with 4 extra fields: 2 check boxes and 2 text fields. And some script. Technical description follows below the pictures.

The next post on this will be with MS CRM 4.0, with buttons as alternative to the checkboxes and with workflows to fill the boxes.

New look and feel Account Form 1

To change the fields on the form, use the check boxes to make the sections shown. Change the regular fields and save the changes.

New look and feel Account Form 2

It is also possible to change only the contents of one of the two boxes.

New look and feel Account Form 3

This is just an example of the possibilities. Hope it helps improving the user experience of MS CRM.

For this example I have created 4 extra field on the account form:

2 text boxes: new_details and new_addressdetails.
2 check boxes:  new_changeaccountinformation and new_changeaddress.

For this example I just made it work, I haven’t build in al the business logic regarding changes in the regular boxes. In the script on the onLoad the text is written and overwritten. But to make clear what does what, I have placed the scripts on the onChange of the specific field it influences.

The Script

Account onLoad script to trigger the onChange scripts:

crmForm.all.new_addressdetails.FireOnChange();
crmForm.all.new_changeaddress.FireOnChange();
crmForm.all.new_details.FireOnChange();
crmForm.all.new_changeaccountinformation.FireOnChange();

new_details onChange script:

/*
copy values to variables
*/
if (crmForm.all.name.DataValue!=null)
{
var name = 'Account Name:\t' + crmForm.all.name.DataValue + '\n';
}
else
{
var name = "";
}

if (crmForm.all.accountnumber.DataValue!=null)
{
var accountnumber = 'Account Number:\t' + crmForm.all.accountnumber.DataValue + '\n';
}
else
{
var accountnumber = "";
}

if (crmForm.all.customertypecode.DataValue!=null)
{
var customertypecode = 'Relationship Type:\t' + crmForm.all.customertypecode.SelectedText + '\n';
}
else
{
var customertypecode = "";
}

if (crmForm.all.telephone1.DataValue!=null)
{
var telephone1 = 'Main Phone:\t' + crmForm.all.telephone1.DataValue + '\n';
}
else
{
var telephone1 = "";
}

if (crmForm.all.telephone2.DataValue!=null)
{
var telephone2 = 'Other Phone:\t' + crmForm.all.telephone2.DataValue + '\n';
}
else
{
var telephone2 = "";
}

if (crmForm.all.fax.DataValue!=null)
{
var fax = 'Fax:\t\t' + crmForm.all.fax.DataValue + '\n';
}
else
{
var fax = "";
}

if (crmForm.all.websiteurl.DataValue!=null)
{

var websiteurl = 'Website:\t\t' + crmForm.all.websiteurl.DataValue + '\n';
}
else
{
var websiteurl = "";
}

if (crmForm.all.emailaddress1.DataValue!=null)
{
var emailaddress1 = 'E-mail:\t\t' + crmForm.all.emailaddress1.DataValue + '\n';
}
else
{
var emailaddress1 = "";
}

if (crmForm.all.parentaccountid.DataValue!=null)
{
var lookup = crmForm.all.parentaccountid.DataValue;
if (lookup[0] != null)
{
var parentaccountid = 'Parent Account:\t' + lookup[0].name + '\n';
}
}
else
{
var parentaccountid = "";
}

if (crmForm.all.primarycontactid.DataValue!=null)
{
var lookup = crmForm.all.primarycontactid.DataValue;
if (lookup[0] != null)
{
var primarycontactid = 'Primary Contact:\t' + lookup[0].name + '\n';
}
}
else
{
var primarycontactid = "";
}

/*
create contents of text box
*/
crmForm.all.new_details.DataValue =
name.toString() +
accountnumber.toString() +
customertypecode.toString() + '\n' +
telephone1.toString() +
telephone2.toString() +
fax.toString() +
websiteurl.toString() +
emailaddress1.toString() +
parentaccountid.toString() +
primarycontactid.toString();
crmForm.all.new_details.ForceSubmit = true;

/*
Change properties of the text box
*/
/*
make field readonly
*/
crmForm.all.new_details.readOnly = true;
/*
make background transparant
*/
crmForm.all.new_details.style.backgroundColor='transparent';
/*
hide scrollbar
*/
document.all.new_details.style.overflow='hidden';
/*
make font bold
*/
document.all.new_details.style.fontWeight='bold';
/*
change left padding
*/
document.all.new_details.style.paddingLeft='10px';
/*
make borders invisible
document.all.new_details.style.border='none';
*/

new_addressdetails onChange script:

/*
copy values to variables
*/
if (crmForm.all.name.DataValue!=null)
{
var name = crmForm.all.name.DataValue + '\n \n';
}
else
{
var name = "";
}

if (crmForm.all.address1_name.DataValue!=null)
{
var addressname = crmForm.all.address1_name.DataValue + ' ';
}
else
{
var addressname = "";
}

if (crmForm.all.address1_addresstypecode.DataValue!=null)
{
var addresstypecode = '('+crmForm.all.address1_addresstypecode.SelectedText +')'+ '\n';
}
else
{
var addresstypecode = "";
}

if (crmForm.all.address1_line1.DataValue!=null)
{
var line1 = crmForm.all.address1_line1.DataValue + '\n';
}
else
{
var line1 = "";
}

if (crmForm.all.address1_line2.DataValue!=null)
{
var line2 = crmForm.all.address1_line2.DataValue + '\n';
}
else
{
var line2 = "";
}

if (crmForm.all.address1_line3.DataValue!=null)
{
var line3 = crmForm.all.address1_line3.DataValue + '\n';
}
else
{
var line3 = "";
}

if (crmForm.all.address1_city.DataValue!=null)
{
var city = crmForm.all.address1_city.DataValue + '\n';
}
else
{
var city = "";
}

if (crmForm.all.address1_stateorprovince.DataValue!=null)
{
var stateorprovince = crmForm.all.address1_stateorprovince.DataValue + ' ';
}
else
{
var stateorprovince = "";
}

if (crmForm.all.address1_postalcode.DataValue!=null)
{
var postalcode = crmForm.all.address1_postalcode.DataValue + ' ';
}
else
{
var postalcode = "";
}

if (crmForm.all.address1_country.DataValue!=null)
{
var country = crmForm.all.address1_country.DataValue + '\n';
}
else
{
var country = "";
}

/*
create contents of text box
*/
crmForm.all.new_addressdetails.DataValue =
name.toString() +
addressname.toString() +
addresstypecode.toString() +
line1.toString() +
line2.toString() +
line3.toString() +
postalcode.toString() +
city.toString() +
stateorprovince.toString() +
country.toString();
crmForm.all.new_addressdetails.ForceSubmit = true;

/*
Change properties of the text box
*/
/*
make field readonly
*/
crmForm.all.new_addressdetails.readOnly = true;
/*
make background transparant
*/
crmForm.all.new_addressdetails.style.backgroundColor='transparent';
/*
hide scrollbar
*/
document.all.new_addressdetails.style.overflow='hidden';
/*
make font bold
*/
document.all.new_addressdetails.style.fontWeight='bold';
/*
change left padding
*/
document.all.new_addressdetails.style.paddingLeft='10px';
/*
make borders invisible
document.all.new_addressdetails.style.border='none';
*/

new_changeaccountinformation onChange script to hide and show the Account Information section:

if (crmForm.all.new_changeaccountinformation.DataValue == "1")
{
crmForm.all.name_c.parentElement.parentElement.parentElement.style.display ='block'
}
else
{
crmForm.all.name_c.parentElement.parentElement.parentElement.style.display ='none'
}

new_changeaddress onChange script to hide and show the Address Details section:

if (crmForm.all.new_changeaddress.DataValue == "1")
{
crmForm.all.address1_name_c.parentElement.parentElement.parentElement.style.display='block'
}
else
{
crmForm.all.address1_name_c.parentElement.parentElement.parentElement.style.display='none'
}