1

I have a requirement where in I need to read all the Names of OpportunityLineItems and then proceed with the logic.

{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/18.0/apex.js")} 

var value1 ={!Opportunity.Probability}; 
alert(value1);
/* Alerts opportunity probability **/

Now what does this return ?

{!OpportunityLineItem.ProductName__c}

Is it an array of OLI names?

Should i read the result as like shown below?

var myArray = new Array();
myArray = {!OpportunityLineItem.ProductName__c} ;

ProductName__c is a formula field populated with Product name.

Am confused and i get error as undefined; Please suggest a better way to read oli names !! Thank you .

1 Answer 1

6

You can read your Opp Line Items depending on the current Opp ID:

{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/18.0/apex.js")} 

// Quering the database
var result = sforce.connection.query("Select ProductName__c From OpportunityLineItem Where OpportunityId = '{!Opportunity.Id}'");

// Getting all records from the query to the array
var records = result.getArray("records");

// Getting the product name of the first array entry
var prodName = records[0].ProductName__c;

alert(prodName);
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .