0

On my Opportunity object:

I have created six custom fields

  • AVSFQB__Generate_Object__c
  • AVSFQB__Quickbooks_Id__c
  • AVSFQB__QuickBooks_ItemType__c
  • Sample_Generate__c
  • Sample_Quickbooks_ID__c
  • Sample_QuickBooks_ItemType__c

I have also created a custom button Process_Sample_Sent

I would like to click the button and move the field contents:

  • AVSFQB__Generate_Object__c to Sample_Generate__c
  • AVSFQB__Quickbooks_Id__c to Sample_Quickbooks_ID__c
  • AVSFQB__QuickBooks_ItemType__c to Sample_QuickBooks_ItemType__c

On the custom button, I have selected:

  • Display type - Detail Page Button
  • Behavior - Execute JavaScript
  • Content Source - OnClick JavaScript

    {!Opportunity.Sample_Generate__c} =     {!Opportunity.AVSFQB__Generate_Object__c} 
    {!Opportunity.Sample_Quickbooks_ID__c} = {!Opportunity.AVSFQB__Quickbooks_Id__c} 
    {!Opportunity.Sample_QuickBooks_ItemType__c} = !Opportunity.AVSFQB__QuickBooks_ItemType__c}
    

This throws an "Unexpected token = " error

Here is my modified code that is throwing the same error.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var record = new sforce.SObject("Opportunity__c");
    record.Id = ("Opportunity__c.Id");
    record.{!Opportunity.Sample_Generate__c} = {!Opportunity.AVSFQB__Generate_Object__c};
var result = sforce.connection.update([record]);
// check the result here
window.location.reload();

Thank you Ardian, Here is the code edited with your suggestion. It is throwing an "Unexpected Identifier" error

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var record = new sforce.SObject("Opportunity__c"); 
record.Id = ("Opportunity__c.Id"); 
record.Sample_Generate__c = {!Opportunity.AVSFQB__Generate_Object__c}; 
var result = sforce.connection.update([record]); 
// check the result here 
window.location.reload();

ARGH.. I didn't mention, AVSFQB__Generate_Object__c is a PICKLIST and Sample_Generate__c is a TEXT field. I am trying to capture the PICKLIST value into the TEST field

2
  • 3
    Hi Stavros, and welcome to SFSE. Take a moment to look at this answer and see if that resolves your problem.
    – sfdcfox
    Commented Jul 27, 2016 at 22:52
  • 1
    Stavros - please use edit to amend your question with the complete onclick Javascript code you are now using
    – cropredy
    Commented Jul 28, 2016 at 4:56

1 Answer 1

0

The correct way to reference the field when setting them is record.Field_Token__c, not record.{!ObjectToken.Field_Token__c}.

Change:

record.{!Opportunity.Sample_Generate__c} = {!Opportunity.AVSFQB__Generate_Object__c};

to:

record.Sample_Generate__c = {!Opportunity.AVSFQB__Generate_Object__c};

You must log in to answer this question.

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