You need to sign in to do that
Don't have an account?
Stavros McGillicuddy
Copy Opportunity Line Items to other fields (see code)
The code below will take all Product Names, Quantities and Total Price for each Opportunity line item of an Opportunity and concatenate them into one custom fields and then delete the Opportunity Line Items. It works flawlessly
For reporting purposes, instead of concatenating into one field I need this code modified to copy the:..
1st Opportunity line item Name and place it in Sample_1_Name__c
2nd Opportunity line item Name and place it in Sample_2_Name__c
3rd Opportunity line item Name and place it in Sample_3_Name__c
4th Opportunity line item Name and place it in Sample_4_Name__c
5th Opportunity line item Name and place it in Sample_5_Name__c
1st Opportunity line item Quantity and place it in Sample_1_Quantity__c
2nd Opportunity line item Quantity and place it in Sample_2_Quantity__c
3rd Opportunity line item Quantity and place it in Sample_3_Quantity__c
4th Opportunity line item Quantity and place it in Sample_4_Quantity__c
5th Opportunity line item Quantity and place it in Sample_5_Quantity__c
1st Opportunity line item Total Price and place it in Sample_1_Price__c
2nd Opportunity line item Total Price and place it in Sample_2_Price__c
3rd Opportunity line item Total Price and place it in Sample_3_Price__c
4th Opportunity line item Total Price and place it in Sample_4_Price__c
5th Opportunity line item Total Price and place it in Sample_5_Price__c
For reporting purposes, instead of concatenating into one field I need this code modified to copy the:..
1st Opportunity line item Name and place it in Sample_1_Name__c
2nd Opportunity line item Name and place it in Sample_2_Name__c
3rd Opportunity line item Name and place it in Sample_3_Name__c
4th Opportunity line item Name and place it in Sample_4_Name__c
5th Opportunity line item Name and place it in Sample_5_Name__c
1st Opportunity line item Quantity and place it in Sample_1_Quantity__c
2nd Opportunity line item Quantity and place it in Sample_2_Quantity__c
3rd Opportunity line item Quantity and place it in Sample_3_Quantity__c
4th Opportunity line item Quantity and place it in Sample_4_Quantity__c
5th Opportunity line item Quantity and place it in Sample_5_Quantity__c
1st Opportunity line item Total Price and place it in Sample_1_Price__c
2nd Opportunity line item Total Price and place it in Sample_2_Price__c
3rd Opportunity line item Total Price and place it in Sample_3_Price__c
4th Opportunity line item Total Price and place it in Sample_4_Price__c
5th Opportunity line item Total Price and place it in Sample_5_Price__c
{!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();
{faultcode:'soapenv:Client'.faultstring:"" is not valid for the type xsd:double',}