jump to navigation

Microsoft Dynamics CRM 4.0 Accessing Parent Form July 28, 2010

Posted by jarrettexpertcrm in Microsoft CRM General.
Tags: , , , , , , , , , ,
add a comment


In some cases you made need to have a code fire based on information from the parent form of that entity. For example, lets say you have a checkbox on the Order form that has values “Approved” and “Unapproved”. You need to have the Product lookup field disabled on the Order Product entity if the value “Unapproved” is checked. This is just an example, there are many other scenarios where this might come in handy. Place this code onload of the child entity.

if (
(window.opener != null) &&
(window.opener.parent != null) &&
(window.opener.parent.document != null) &&
(window.opener.parent.document.crmForm != null)) {

var parentForm = window.opener.parent.document.crmForm;
var formType;

switch(parentForm.FormType)
{

case 1:
formType = “Create Form”;
break;

case 2:
formType = “Update Form”;
break;

case 3:
formType = “Read Only Form”;
break;

case 4:
formType = “Disabled Form”;
break;

case 5:
formType = “Quick Create Form”;
break;

case 6:
formType = “Bulk Edit Form”;
break;

default:
formType = “Undefined Form Type”;
break;
}

if (parentForm.ObjectTypeName == “PARENTENTITY”)
{

if(parentForm.all.FIELD.DataValue == VALUE)

{
//PLACE FUNCTION FOR CHILD ENTITY HERE

}

}
}

Enjoy!

For more information about Dynamics Four or to contact us please visit http://www.dynamics4.com

Microsoft Dynamics CRM 4.0 Primary Contact Filter July 14, 2010

Posted by jarrettexpertcrm in Microsoft CRM General.
Tags: , , , , , , , , , ,
add a comment

I have received quite a few requests to have primary contact on accounts, when clicked, only show the contacts for that particular account. For those that may already have some sort of look up filter in place they may have experienced this problem, and for those that don’t, well here is a solution that will work. When in an account with a “&” in the name, you click primary contact and you receive an error. Here is a fix for that.

Account Onload:

if (crmForm.FormType == 2 && crmForm.ObjectId != null)
{
var name = crmForm.all.name.DataValue;
crmForm.all.primarycontactid.additionalparams =  ‘search=’ + name.replace(“&”,”%26″).replace(“+”,”%2b”);
}
Hope this helps!
For more information about Dynamics Four or to contact us please visit http://www.dynamics4.com

Setting a default value on a lookup field in Microsoft Dynamics CRM 4.0 October 27, 2009

Posted by jarrettexpertcrm in Microsoft CRM General.
Tags: , , , , , , , ,
8 comments

d4 logo I got a request to set the “Unit” on an Opportunity Product to always default to “Primary unit” when a product is created. Setting default values on lookup fields seems to be a common request, so i decided to post the code to achieve this. This is an Onload Event.

//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
   lookupItem.id = ‘{299F37C4-6D9D-4628-ADF9-9479A6F209BA}’;
   lookupItem.typename = ‘uom’;
   lookupItem.name = ‘Primary Unit’;
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.uomid.DataValue = lookupData;

If you want to use this code for other lookups, here is what you need to change:

//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
   lookupItem.id = ‘{Fields Guid}’;
   lookupItem.typename = ‘Entity Name’;
   lookupItem.name = Lookup Value;
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.FieldName.DataValue = lookupData;

Enjoy!!

For more information about Dynamics Four you can contact us at http://www.dynamics4.com