You need to sign in to do that
Don't have an account?
![Mateo Alcauter Mateo Alcauter](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
javascript custom button
Hello,
I have a button on Transaction__c (which is a custom object) to submit a transaction for approval. This would make the transaction go through an approval process where it first checks if this transaction has the requirements to be submited for approval.
I'm attempting to create a javascript in which someone can select multiple transactions and mass submit them for approval.
My code does not work when a transaction doesn't meet the requirements. It only works if all the transactions selected meet the requirements.
This means if i select 2 transactions, 1 meets the requirements, 1 doesn't, it fails completely and won't even submit the one that does meet the requiments.
"Submit_for_Approval__c" is a checkbox that when = true will automatically start the approval process.
Here is the code:
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
var records1 = {!GETRECORDIDS($ObjectType.Transaction__c)};
var myquery = 'SELECT Id, Submit_for_Approval__c FROM Transaction__c WHERE Id in (\'' + records1.join('\',\'') + '\')';
var queryResults = sforce.connection.query(myquery);
var records = queryResults.getArray("records");
var cycleTrans = new Array;
var r = confirm('Are you sure you want to submit ' + records.length + ' transactions for approval?');
if (records.length == null)
{
alert('Please select a record');
}
else
{
if (r == true) {
for (var i=0; i<records.length; i++)
{
var myObj = records[i];
myObj.Submit_for_Approval__c = true;
cycleTrans.push(myObj);
}
alert('Submitted transactions for approval');
result = sforce.connection.update(cycleTrans);
}
}
I have a button on Transaction__c (which is a custom object) to submit a transaction for approval. This would make the transaction go through an approval process where it first checks if this transaction has the requirements to be submited for approval.
I'm attempting to create a javascript in which someone can select multiple transactions and mass submit them for approval.
My code does not work when a transaction doesn't meet the requirements. It only works if all the transactions selected meet the requirements.
This means if i select 2 transactions, 1 meets the requirements, 1 doesn't, it fails completely and won't even submit the one that does meet the requiments.
"Submit_for_Approval__c" is a checkbox that when = true will automatically start the approval process.
Here is the code:
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
var records1 = {!GETRECORDIDS($ObjectType.Transaction__c)};
var myquery = 'SELECT Id, Submit_for_Approval__c FROM Transaction__c WHERE Id in (\'' + records1.join('\',\'') + '\')';
var queryResults = sforce.connection.query(myquery);
var records = queryResults.getArray("records");
var cycleTrans = new Array;
var r = confirm('Are you sure you want to submit ' + records.length + ' transactions for approval?');
if (records.length == null)
{
alert('Please select a record');
}
else
{
if (r == true) {
for (var i=0; i<records.length; i++)
{
var myObj = records[i];
myObj.Submit_for_Approval__c = true;
cycleTrans.push(myObj);
}
alert('Submitted transactions for approval');
result = sforce.connection.update(cycleTrans);
}
}
![Mateo Alcauter Mateo Alcauter](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
OR. how do i sforce.connection.update for individual records instead of the whole array?