You need to sign in to do that
Don't have an account?
Cray Kao
How to display field value within a javascript button script (for loop)
Here is a list button to display selected records.
If I want to display the contact name instead of "id of the contact" and also prevent from displaying those whom is "DoNotCall".
How to modify the button script?
And I am new to Salesforce Developer, and which board will more suitable to discuss javascript button questions. Thanks.
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Contact)};
if (records[0] == null)
{
alert("Please select at least one record")
}
else{
for (var n in records) {
alert ( records[n] ) }
}
Hi,
Try below code snippet as reference:
{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Contact)};
if(records[0]==null)
{
alert('Please select altleat one contact');
}
else
{
if(records.length>1)
{
var querydata='';
querydata='\''+records [0]+'\'';
for(var i=1;i<records .length;i++)
{
querydata=querydata+',\''+records [i]+'\'';
}
}
else
{
querydata='\''+records+'\'';
}
var query1='select name from contact where id in('+querydata+')';
var result =sforce.connection.query(query1);
//for(var j=0;j<result.length;i++)
{
for(var i=0;i<result.size;i++)
{
var res=result['records'][i];
alert(res['Name']);
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
If I do a little modify...
it will show "0", "undefined", "id of record 0", then "1", "undefined", "id of record 1"
How to show object__c.name in such an array?
Thanks
Here's the code:
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.object__c)};
if (records[0] == null)
{
alert("Please select at least one record")
}
else{
for (var n in records) {
alert ( n );
alert ( n.name );
alert ( records[n] ) }
}
Hi,
Try below code snippet as reference:
{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Contact)};
if(records[0]==null)
{
alert('Please select altleat one contact');
}
else
{
if(records.length>1)
{
var querydata='';
querydata='\''+records [0]+'\'';
for(var i=1;i<records .length;i++)
{
querydata=querydata+',\''+records [i]+'\'';
}
}
else
{
querydata='\''+records+'\'';
}
var query1='select name from contact where id in('+querydata+')';
var result =sforce.connection.query(query1);
//for(var j=0;j<result.length;i++)
{
for(var i=0;i<result.size;i++)
{
var res=result['records'][i];
alert(res['Name']);
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Cool & Thanks