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

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.'); 
}
  • 2
    No dot after create – Eric Feb 28 '17 at 13:48
  • Thanks Fernando,not working after removing the dot also – prasad nagamalli Feb 28 '17 at 16:19
  • @prasadnagamalli I just spotted a few more errors and updated the answer. Take a look =D – Fernando Gavinho Feb 28 '17 at 16:57
  • did the changes you suggested, but issue was not resolved fernando – prasad nagamalli Mar 2 '17 at 6:46
  • Is the message still unexpected token error? – Fernando Gavinho Mar 2 '17 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.