You need to sign in to do that
Don't have an account?

Code only moves first two characters of a field. Please see code
This code queries the current opportunity's line item Name, Quantity, TotalPrice and Description and places them into custom fields and executes without error.
The problem is it only places the first two characters of the Name.
The receiving field is a text (100) field
By commenting out this line, it works as expected but I don’t know how to fix it.
I was graciously helped with this by the community so I am not sure what this line is supposed to do or if I even need it
if(strProductNames.length>0){ strProductNames = strProductNames.substring(0,strProductNames.length-2); }
The problem is it only places the first two characters of the Name.
The receiving field is a text (100) field
By commenting out this line, it works as expected but I don’t know how to fix it.
I was graciously helped with this by the community so I am not sure what this line is supposed to do or if I even need it
if(strProductNames.length>0){ strProductNames = strProductNames.substring(0,strProductNames.length-2); }
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} var record = new sforce.SObject("Opportunity"); record.Id = '{!Opportunity.Id}'; result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice, Description, ServiceDate From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')"); records = result.getArray("records"); var strProductNames = ''; var strProductQuantity = ''; var strProductPrice = ''; var strDescription = ''; var strServiceDate = ''; for(var i=0; i<records.length ; i++){ strProductNames = records[i].PricebookEntry.Product2.Name strProductQuantity = records[i].Quantity strProductPrice = records[i].TotalPrice strDescription = records[i].Description strServiceDate = records[i].ServiceDate; } if(strProductNames.length>0){ strProductNames = strProductNames.substring(0,strProductNames.length-2); } record.Sample_Name__c = strProductNames; record.Sample_Quantity__c = strProductQuantity; record.Sample_Price__c = strProductPrice; record.Sample_Description__c = strDescription; record.Sample_Service_Date__c =strServiceDate; sforce.connection.update([record]); window.location.reload();
If you are sure about the number of characters of "PricebookEntry.Product2.Name " data is not more than 100 character then you dont need
below lines of code
you can simply comment it out.
If you are not sure about the length of this field data then you need to either increase the length of field "record.Sample_Name__c" or you have to truncate the original size of to "PricebookEntry.Product2.Name " to 100 by doing this
try this should work for you and let us know if you still have issue.
All Answers
If you are sure about the number of characters of "PricebookEntry.Product2.Name " data is not more than 100 character then you dont need
below lines of code
you can simply comment it out.
If you are not sure about the length of this field data then you need to either increase the length of field "record.Sample_Name__c" or you have to truncate the original size of to "PricebookEntry.Product2.Name " to 100 by doing this
try this should work for you and let us know if you still have issue.