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

Quote Button not working
Hello all, I created this button on the Quote object to create QuoteLineItems but it's not working. Below is the code BUT please see my note below the code for some clarification:
{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")}
var pricebookid = "01s60000000AaPr";
var quoteId = "{!Quote.Id}";
var quoteQuery = sforce.connection.query("Select Id, Name FROM Quote WHERE Id='" + quoteId + "'");
var quotyResult = quoteQuery.getArray("records");
quotyResult[0].Pricebook2Id = pricebookid;
var updatequotyResult = sforce.connection.update([quotyResult[0]]);
var result = sforce.connection.query("Select Id,Name,HE__c,HE_Qauntity__c,Price_Book_Entry_ID__c From Product2 Where HE__c = TRUE");
var records = result.getArray("records");
var CreateRecords=[];
if(records[0]==null)
alert('No Product Set is Retrieved!');
for(var i=0;i<records.length;i++)
{
var linky=new sforce.SObject("QuoteLineItem");
linky.QuoteID = '{!Quote.Id}';
linky.PriceBookEntryId = records[i].Price_Book_Entry_ID__c;
linky.Quantity = records[i].HE_Qauntity__c;
linky.UnitPrice = 1;
linky.Quoting_Tool__c = 1;
CreateRecords.push(linky);
}
result=sforce.connection.create([CreateRecords]);
alert(result);
window.location.reload();
// The code works fine if I create them one by one within the loop but I wanted to create them at once from an array. For example, if I put
result=sforce.connection.create([linky]);
in the loop it works fine but slow. That's whay I wanted to go the other way around to create them at once from an array. Please help.
{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")}
var pricebookid = "01s60000000AaPr";
var quoteId = "{!Quote.Id}";
var quoteQuery = sforce.connection.query("Select Id, Name FROM Quote WHERE Id='" + quoteId + "'");
var quotyResult = quoteQuery.getArray("records");
quotyResult[0].Pricebook2Id = pricebookid;
var updatequotyResult = sforce.connection.update([quotyResult[0]]);
var result = sforce.connection.query("Select Id,Name,HE__c,HE_Qauntity__c,Price_Book_Entry_ID__c From Product2 Where HE__c = TRUE");
var records = result.getArray("records");
var CreateRecords=[];
if(records[0]==null)
alert('No Product Set is Retrieved!');
for(var i=0;i<records.length;i++)
{
var linky=new sforce.SObject("QuoteLineItem");
linky.QuoteID = '{!Quote.Id}';
linky.PriceBookEntryId = records[i].Price_Book_Entry_ID__c;
linky.Quantity = records[i].HE_Qauntity__c;
linky.UnitPrice = 1;
linky.Quoting_Tool__c = 1;
CreateRecords.push(linky);
}
result=sforce.connection.create([CreateRecords]);
alert(result);
window.location.reload();
// The code works fine if I create them one by one within the loop but I wanted to create them at once from an array. For example, if I put
result=sforce.connection.create([linky]);
in the loop it works fine but slow. That's whay I wanted to go the other way around to create them at once from an array. Please help.
result=sforce.connection.create(CreateRecords);
All Answers
result=sforce.connection.create(CreateRecords);