Reply
Trusted Contributor
ckellie
Posts: 411
0
Accepted Solution

Custom Button with Javascript

I am not sure if this is the correct board for this question. if it is not, would someone point me to the correct board?

 

 

From the quotelineitem related list area of the quote page, I am trying to write query inside the javascript in the custom button. Upon testing I recieve the following error:

A problem with the OnClick JavaScript for this button or link was encountered:

missing ; before statement

Here is the custom button.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")};

var records = {!GETRECORDIDS($ObjectType.QuoteLineItem)};

var recordtype = sforce.connection.query("select id from recordtype where name = 'Autoconfig' ");
$newrecord{"id"} = @{$field->{'Id'}}[0];
var CreateNewRecords = [];
try
{

if (records[0] == null)
{
    alert("Please select at least one record to update.");
}
else
 {
    for (var a=0; a<records.length; a++)
    {
        var create_new_Quote = new sforce.SObject("Quote");
        create_new_Quote.RecordTypeId = recordtype;
        create_new_Quote.Opportunityid = "006P0000003ahP5";
        create_new_Quote.name = "AutoConfig trigger";
        CreateNewRecords.push(create_new_Quote);
    }
var result = sforce.connection.create(CreateNewRecords);
if (result[0].success=='false')
{
    alert(result[0].errors.message);
}
else
{
    location.reload(true);
}

}
}
catch(error)
{
alert("Error In Quote creation  = "+error);
}

 How do I correct my error?

Super Contributor
Rahul Sharma
Posts: 848
0

Re: Custom Button with Javascript

ckellie, I would like to know what below line of code does.

$newrecord{"id"} = @{$field->{'Id'}}[0];

For debugging cause of problem, try inserting alerts in different loops or line.

- Rahul
Trusted Contributor
ckellie
Posts: 411
0

Re: Custom Button with Javascript

Rahul,

I have pulled this code from an example I found and am not sure what that line states.

Super Contributor
Rahul Sharma
Posts: 848
0

Re: Custom Button with Javascript

ckellie, Just curious to know, were you able to find the solution?

- Rahul
Trusted Contributor
ckellie
Posts: 411
0

Re: Custom Button with Javascript

Rahul,

 

Thanks for asking. I found a completely different solution to what I was looking for.

 

// Include and initialize the AJAX toolkit library
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")};
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")};
var idList = {!GETRECORDIDS($ObjectType.QuoteLineItem)};
var retURL = window.location.toString();
var proceed = true;
if(idList.length > 1 || idList.length == 0){
alert('Please select 1 record.');
proceed = false;
}

if(idList.length == 1){
window.location="/apex/selectProductOptionsv8?qli=" + idList;
}

 Thank you for your help