function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MigMig 

Problem with List button onclick Javascript

Hi,

I created a List Button :

List Button code :
Code:
{!RequireScript("/js/functions.js")}

var recordsToTransfer = {!GetRecordIds($ObjectType.Order__c)}

function init(){
if(recordsToTransfer.length < 1){
alert(" Please Select a value") ;
}

else if (!document.elementsAddedToPage)
{
for(var i=0; i < recordsToTransfer.length ; i++) {
Edit(recordsToTransfer[i]);
}
}
}
function Edit(OrderID){
var Edit = new sforce.SObject("Order__c");
Edit.Id = OrderID;
Edit.Order_Status__c = "Ready";
var result = sforce.connection.update([Edit]);
window.location.reload();
}

init();

This code will change the Status of the selected Orders. It works fine But a few times (in I.E. 7.0)  I've got a weird error :

Something like : 'Error On Click Javascript  Sforce is not defined ';

Please, can someone help me on this ? I don't understand this error. (Apparently It's only for some no Admin Profile users... and always in I.E. 7.0 even if I had that error once in firefox in admin profile :s but once I refreshed it was ok) I tryed already to update I.E, but does not work!

Thank you in advance for your help; this is really very important ...

Mig


Message Edited by Mig on 02-12-2008 01:13 PM
MigMig
I tryed to add this :

Code:
{!RequireScript("/soap/ajax/11.0/connection.js")} 

I have no idea if it will change something ...
 

NaishadhNaishadh
Hi Mig,

You need to add first connection.js and then function.js also check which js file version u r using.
TCAdminTCAdmin
Hello Mig,

You should only need to include one of the RequiredScript tags since that is what determines what commands you use. If you use the first code below it will give you all of the recent API commands. I also included an Execute JavaScript button code to update the Contact addresses as an example.

Code:
{!REQUIRESCRIPT("/soap/ajax/12.0/connection.js")} 

 
Code:
{!REQUIRESCRIPT("/soap/ajax/12.0/connection.js")} 

var getContacts = sforce.connection.query("Select c.Id From Contact c WHERE c.AccountId = '{!Account.Id}'"); 
var contactRecords = getContacts.getArray("records"); 
var error = false; 

if(contactRecords.length > 0){ 
var getAccAddress = sforce.connection.query("Select a.BillingStreet, a.BillingState, a.BillingPostalCode, a.BillingCountry, a.BillingCity From Account a WHERE a.Id = '{!Account.Id}'"); 
var accRecords = getAccAddress.getArray("records"); 

if(accRecords.length > 0){ 
var thisAcc = accRecords[0]; 
var billStreet = thisAcc.BillingStreet; 
var billState = thisAcc.BillingState; 
var billCode = thisAcc.BillingPostalCode; 
var billCountry = thisAcc.BillingCountry; 
var billCity = thisAcc.BillingCity; 

// Update contact addresses 

for(i=0;i<contactRecords.length;i++){ 
thisContact = contactRecords[i]; 
thisContact.MailingStreet = billStreet; 
thisContact.MailingState = billState; 
thisContact.MailingPostalCode = billCode; 
thisContact.MailingCountry = billCountry; 
thisContact.MailingCity = billCity; 
contactRecords[i] = thisContact; 
} // END for loop populating contact information 

// Save updated Contacts 

var saveResults = sforce.connection.update(contactRecords); 

for(i=0;i<contactRecords.length;i++){ 

if(saveResults[i].success == 'false'){ 
alert(saveResults[i].errors.message + " " + saveResults[i].errors.statusCode); 
error = true; 
} // END if statement to notify if error occurs 

} // END for loop 

// Notify user updates completed 

if(!error){ 
alert('Contacts Updated'); 
} // END user notification 

} else { 
alert('No Contacts associated or an error has occured, please verify and contact administrator'); 
} // END else of the if statement. If there was an Account returned from the query 

}// END if statement 
Description 

 Forgive the formatting of the code, I don't have the development tool to get the original code here.

Please let me know if you have questions.
MigMig
Tkx both for your reply =)
Indeed it works fine !