aug 11 Java Javascript Microsoft CRM

Setting defaul values in CRM

Hi all,

Here is a nice little collection of examples on how to set default values with javascript:

http://msdn.microsoft.com/en-us/library/cc468412.aspx

var CRM_FORM_TYPE_CREATE = “1”;

if (crmForm.FormType==CRM_FORM_TYPE_CREATE)

{

// Set the value of the topic field.

var topic = crmForm.all.name;

topic.DataValue = “New Opportunity: “;

// Price List – a lookup field.

var priceList = crmForm.all.pricelevelid;

// Do Not overwrite an existing value that may be mapped.

if (priceList.DataValue == null)

{

// Create an array to set as the DataValue for the lookup control.

var lookupData = new Array();

// Create an object to add to the array.

var lookupItem= new Object();

// Set the id, typename, and name properties to the object.

lookupItem.id = ‘{1726C802-22CA-DC11-BE78-0003FF9EE217}';

lookupItem.typename = ‘pricelevel';

lookupItem.name = ‘Retail';

// Add the object to the array.

lookupData[0] = lookupItem;

// Set the value of the lookup field to the value of the array.

priceList.DataValue = lookupData;

}

// Set the currency before the revenue amount can be set.

var currency = crmForm.all.transactioncurrencyid;

// Do Not overwrite an existing value that may be mapped.

if (currency.DataValue == null)

{

// 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 = ‘{F84F576A-3EC9-DC11-A8D2-0003FF9EE217}';

lookupItem.typename = ‘transactioncurrency';

lookupItem.name = ‘US Dollar';

// Add the object to the array.

lookupData[0] = lookupItem;

// Set the value of the lookup field to the value of the array.

currency.DataValue = lookupData;

}

// Set the Estimated Revenue.

var estRev = crmForm.all.estimatedvalue;

// Only set the default if the currency is US Dollar.

if (currency.DataValue[0].name == ‘US Dollar’)

{

estRev.DataValue = 1000;

}

// Set the Est Close Date field.

var estCloseDate = crmForm.all.estimatedclosedate;

var oToday = new Date();

var todaysDate = oToday.getDate();

// Set the date 5 days into the future.

var DueDate = todaysDate + 5;

var oDate = oToday;

oDate = oDate.setDate(DueDate);

estCloseDate.DataValue = oDate;

// Set the Description Field.

var description = crmForm.all.description;

var message = “Don’t forget to include a short “;

message += “description of the opportunity here.”;

description.DataValue = message;

}

Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+

Skriv et svar

Din e-mailadresse vil ikke blive offentliggjort. Krævede felter er markeret med *