0

How to create a Custom button to create a new record in other object?

I tried by using javascript code to create a new record i am getting:

Unexpected token error

my code is

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

var curnc= new sforce.Sobject(TR_Currency_Approval__c); 
curnc.currency={!TR_Currency__c.CurrencyIsoCode}; 
curnc.Active__c={!TR_Currency__c.Active__c}; 
curnc.Description__c={!TR_Currency__c.Description__c}; 

result=sforce.connection.create.([curnc]); 

if(result[0].success == 'true'){ 
alert('An New Currency Approval with Name - ' + curnc.currency + ' was Created Successfully.'); 
}

is there any other way to achieve this

1 Answer 1

1

You need to

  • Enclose the values in quotes
  • Declare result as a variable and remove the dot after create:
  • Maybe need to correct the SObject method (capitalisation)
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 

var curnc= new sforce.SObject(TR_Currency_Approval__c); 
curnc.currency='{!TR_Currency__c.CurrencyIsoCode}'; 
curnc.Active__c='{!TR_Currency__c.Active__c}'; 
curnc.Description__c='{!TR_Currency__c.Description__c}'; 

var result=sforce.connection.create([curnc]); 

if(result[0].success == 'true'){ 
alert('An New Currency Approval with Name - ' + curnc.currency + ' was Created Successfully.'); 
}
5
  • 2
    No dot after create
    – Eric
    Feb 28, 2017 at 13:48
  • Thanks Fernando,not working after removing the dot also Feb 28, 2017 at 16:19
  • @prasadnagamalli I just spotted a few more errors and updated the answer. Take a look =D Feb 28, 2017 at 16:57
  • did the changes you suggested, but issue was not resolved fernando Mar 2, 2017 at 6:46
  • Is the message still unexpected token error? Mar 2, 2017 at 9:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .