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
Samantha ChuaSamantha Chua 

How do I concatenate Merge Fields in Javascript Custom Button?

Hi Guys!

I am creating this custom button. What it does is that it will create a contract and push values from opportunity over, whenever it is being clicked.

Running into a problem here as I am trying to make my contract name = Opportunity contract type + Opportunity product + opportunity account name.

How do i do the concatenation?

Here is a snippet of my codes:
 
c.Name = "{!Opportunity.Contract_Type__c}"; + "{!Opportunity.Account}";



Any help is greatly appreciated!

Regards,
Samantha (:
BALAJI CHBALAJI CH
Hi Samantha,

I did not understand how you using c.Name in JavaScript.
But to concatenate Merge fields in JavaScript,
var contractname = '{!Opportunity.Contract_Type__c}' + ' ' + '{!Opportunity.Account}';
You can assign this variable contractname to the Inserting Contract's Name.

Let us know if that helps you.

Best Regards,
BALAJI

 
Nagendra ChinchinadaNagendra Chinchinada
Hi Samanths,

Put below code in button and try.  It will defenitly work
 
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}

var connection = sforce.connection;//Create connection
var newContract = new sforce.SObject("Contract__c");//initiate sObject(replace contract__c with your objects API name)
newContract.Name = '{!Opportunity.Contract_Type__c}' + ' ' + '{!Opportunity.Account}';//Assign Name from Opportunity
// Populate remaining fields of contract from Opportunity here
//newContract.Opportunity__c = '{!Opportunity.Id}';

result = sforce.connection.create([newContract]);//Insert Contract

if(result[0].getBoolean("success")){//If insert is success
alert('Contract created succesfully');
location.reload();
}else//If insert failed
alert('Error Occurred while creating contract');
Let me know if it helps.