{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';
//copy opportunity line items
result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')");
records = result.getArray("records");
var strProductNames = '';
for(var i=0; i<records.length ; i++){
strProductNames += 'PRODUCT NAME: ' + records[i].PricebookEntry.Product2.Name + ' --- QUANTITY: ' + records[i].Quantity + ' --- TOTAL PRICE: $ ' + records[i].TotalPrice +',\n';
}
if(strProductNames.length>0){
strProductNames = strProductNames.substring(0,strProductNames.length-2);
}
record.Samples_Sent__c = strProductNames;
//delete opportunity line items
var lineItems = sforce.connection.query("select id from opportunitylineitem where opportunityid = '{!Opportunity.Id}'")
var oliIds = []
var qri = new sforce.QueryResultIterator(lineItems)
while(qri.hasNext())
oliIds.push(qri.next().Id)
sforce.connection.deleteIds(oliIds)
sforce.connection.update([record]);
window.location.reload();
Changing the field type of Sample_Quantity__c from number to text and Sample_Price_cc from currency to text stopped the error so I have to believe there is something wrong with my syntax. Sample_Name_cc populated as expected. Sample_Quantity_cc populated as expected. Sample_Price_cc did not poplate at all.