How to default a Picklist in a new record of a child business component

A user may wish to default the picklist value of a child business component with the value from a field in the parent business component. Setting the "Predefault value" does not work to default the picklist in the child business component because the picklist is independent of the parent BC. Picklists are independent because they can be used across multiple business components.

Option #1:

Use Business Component User Property "Picklist Pre Default Field n". 

Example:

Name: Picklist Pre Default Field 1
Value: "Period Name", "'CPG Plan Account Promotion.Period Name'"


Option #2:

If other fields are dependent on the picklist, scripting can be used to simulate the picklist behavior. For example, for Promotions, the Period Start Date and Period End Date fields are populated based on the Period selected in the picklist. If the Business Component User Property"Picklist Pre Default Field n" is used, the Period Start Date and Period End Date fields are not populated with default values on the New Record.

Scripting Steps:

1) In the “Parent” BusComp_ChangeRecord event you set the required field value as a global variable using the application SetSharedGlobal method.
2) In Pick Business Component BusComp_NewRecord event you write a script that retrieves the global variable (from step 1) using the application GetSharedGlobal method.
3) Set the correct field value using the appropriate method (SetFieldValue for standard fields or using the Pick functionality for Join fields).

Sample Script for New Record:
 

var oPromoBO = TheApplication().ActiveBusObject();
var oPromoBC = oPromoBO.GetBusComp("CPG Plan Account");
var period = oPromoBC.GetFieldValue("Period Id");
var pickBusComp = this.GetPicklistBusComp("Period Name");
with (pickBusComp)
{
ClearToQuery();
SetSearchSpec("Id", period);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
pickBusComp.Pick();
}
pickBusComp = null;
Tags
Recent content