Installation and Setup > Customizing ServiceMax > Using Product from Opportunity Line in SFM Transactions
Using Product from Opportunity Line in SFM Transactions
Additional customization is required to use the Product field in SFM Transactions. Follow the instructions below.
To use Product from Opportunity Line in an SFM Transaction:
1. In the Opportunity Product object, create a field of type Lookup to Product as Opportunity_Product__c (field label: Opportunity Product).
2. Create a trigger as follows for the Opportunity Product object:
// When a new line item is added to an opportunity, this trigger copies the value of the associated product's ID to the record.
trigger PopulateProductLookup on OpportunityLineItem (before insert)
{
// For every OpportunityLineItem record, add its associated pricebookentry to a set so there are no duplicates.
Set<Id> pbeIds = new Set<Id>();
for (OpportunityLineItem oli : Trigger.new)
pbeIds.add(oli.pricebookentryid);
// Query the PricebookEntries for their associated product and place the results in a map.
Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>([select product2.id from pricebookentry where id in :pbeIds]);
// Now use the map to set the appropriate product on every OpportunityLineItem processed by the trigger.
for (OpportunityLineItem oli : Trigger.new)
oli.Opportunity_Product__c = entries.get(oli.pricebookEntryId).product2.id;
}
3. If there is a need to populate the Opportunity Product custom field for the existing Opportunity Product records, change the definition of the trigger to (before insert, before update), and update all the existing Opportunity Product records.
4. In the SFM transaction for Opportunity to any target object, map the target object's Product Lookup field to Opportunity Product’s Opportunity Product field.
Was this helpful?