function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Stavros McGillicuddyStavros McGillicuddy 

Syntax to reference Opportunity>Product Line Items

My opportunities may have up to 4 products (line items) attached to them.
I am looking for the syntax to copy the 4 Opportunity > Product Names to 4 custom fiedls on the Opportunity object

This does not throw an error but it does nothing
record.Sample_Product_Name_2__c='{!Product2.Name}';

 
Stavros McGillicuddyStavros McGillicuddy
More experimenting..

This throws an OpporunityLineItem not defined error and, I'm not sure how to find all line items
Thank you
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 

var record = new sforce.SObject("Opportunity"); 
record.Id = '{!Opportunity.Id}'; 

record.Sample_Product_Name_1__c=OpportunityLineItem.PricebookEntry.Name; 
record.Sample_Product_Name_2__c= <<The next line item Name>>; 
record.Sample_Product_Name_3__c= <<The next line item Name>>; 
record.Sample_Product_Name_4__c= <<The next line item Name>>; 

sforce.connection.update([record]); 
window.location.reload();