Tag Archives: Client Side Scripting

A simple “day of the week” script

Some months ago a customer asked us if it was possible to prevent users from selecting a Saturday or Sunday in a date field. Here is a simple function you can use to call the selected day of the week. You can customize it to suit your own wishes. Please remember that Sunday is 0 and Saturday is 6.

Happy Easter!

function weekday () {
//Script to show which weekday the selected date is.
//Sunday = 0, Saturday = 6
//Script to be called during Onchange event

/* CRM 3.0 & 4.0 */ selectedDate = crmForm.all.estimatedclosedate.DataValue;
/* CRM 2011 */ selectedDate = Xrm.Page.data.entity.attributes.get("estimatedclosedate");
var weekday = selectedDate.getDay();
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

alert("You have selected a " + dayNames[weekday]);
}
Tagged as: , , ,

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars (2 votes, average: 6.00 out of 7)
Loading ... Loading ...

ISV button with onLoad function

It took me too long to figure out how to put my extensive JavaScript code into the ISV.config xml. Eventually it worked, but a far more easier way is to trigger the JavaScript, is to put a function name in the xml file and put the contents of the function in the onLoad of your form. As I reminder to myself, I stored it over here.
(In case the ISV button is not placed on the a form, but for example on a view, than you still have to put the JavaScript into the xml file.)
Here is a xml example of the ISV.config part:
XML code
And the onLoad script example:

Function_onclick = function()
{
alert('Button has been clicked');
}
Tagged as: , ,

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars (1 votes, average: 3.00 out of 7)
Loading ... Loading ...

Improving GUI (static) information on forms

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.

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

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

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'
}
Tagged as: , , ,

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars (1 votes, average: 6.00 out of 7)
Loading ... Loading ...
Page 1 of 512345
  • Recent Posts

  • Ratings

  • Archive

  • Admin

  • Cloud

  • Microsoft Certified Professional

  • About & Contact