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
john4sfdcjohn4sfdc 

how to refer custon setting fields in javascript button code

I need to refer a custom settting field in the Javascript button.

How do we refer custo setting values in Java script button code

john4sfdcjohn4sfdc

Hi Sam,

i need to call them and use them in my Java script button logic. When i use as mentioned in the above link, It says Merge field not valid

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

I've tested the below code for a button and it works..

 

{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")}
var a = "{!$Setup.TestH__c.EnabledH__c}"; //TestH__c--> Custom setting API Name, EnabledH__c-->Field API Name, Custom Setting Type: Hierarchy
alert('This is Cust Setting>> '+a);

 

If your's is still not working post your code and let me know what kind of custom setting you are using.

john4sfdcjohn4sfdc

Hi Sam,

i have the following custo setting created

CustomAPi Name: Docusignmsg__c

Field1 name:Email_message__c

Field2name: Text_Subject__c

i am using list type

 

 

 

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")}

var result = sforce.connection.query("Select Name, Email_message__c,Text_Subject__c from Docusignmsg__c");
records = result.getArray("records");

for (var i=0; i< records.length; i++) {
alert('List Setting Name@@@ ' + records[i].Name);

alert('List Setting Email_message__c@@@ ' + records[i].Email_message__c);

alert('List Setting Text_Subject__c @@@ ' + records[i].Text_Subject__c );
}

priyanshu nemapriyanshu nema
Hi,
This below code working for update hierarchy type custom setting by javascript button.

 {!REQUIRESCRIPT("/soap/ajax/40.0/connection.js") } 
{!REQUIRESCRIPT("/soap/ajax/40.0/apex.js") } 
sforce.connection.sessionId = "{!$Api.Session_ID}";
var userId = '{!$User.Id}';            // it's provide current user
var query = sforce.connection.query("select id from Scholarship_Detail__c where SetupOwnerId ='"+ userId+"'"); // customSetting
var recordId = query.getArray("records");
if(recordId.length > 0){
var i = recordId[0].Id;
}
var Scholarship_Detail_obj =new sforce.SObject("Scholarship_Detail__c");
var Scholarship = new sforce.SObject('Scholarship__c');
Scholarship.Id = '{!Scholarship__c.Id}';
Scholarship_Detail_obj.id = i;
Scholarship_Detail_obj.SetupOwnerId = userId;
Scholarship_Detail_obj.Scholarship_Id__c = '{!Scholarship__c.Id}';
var result = sforce.connection.update([Scholarship_Detail_obj]);


and if you want to create custom setting than use below line 
var result = sforce.connection.create([Scholarship_Detail_obj]);