How to get Product Name from Opportunity using Groovy
I have a requirement to concatenate Account Name + Product Name as Opportunity Name in Opportunity creation page. I use BeforeInsert object trigger for this. I can get the Account name but I find it hard to get the Product name when I select a product item in the name field.
Please modify my groovy script, as this get the first existing element (product) not the product I selected.
// Set Opportunity Name to Account Name + Product
def voProduct = newView('Product');
def vcProduct = voProduct.createViewCriteria();
def vcrProduct = vcProduct.createRow();
vcProduct.insertRow(vcrProduct);
voProduct.appendViewCriteria(vcProduct);
voProduct.executeQuery();
def prodName = voProduct.first()?.getAttribute('Name');