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
splashgordonsplashgordon 

Custom button to copy data between custom objects

 

I need to create a custom button on a custom object ("Signoff") that copies data from a related record on another custom object ("Delivery Project").

Every "Signoff" is related to a "Delivery Project" via a standard lookup. What I would like is a button called "Get Baseline" that, when pressed, copies the data from various fields from the related Delivery project record to the equivalent fields in the Signoff record. I have placed the following Java code in a custom button I have already created but, not being a Java person, this is not working:

{!Signoff__c.Previous_Delivery_Date__c} = {!Delivery_Project__c.Baseline_Delivery_Date__c}

I suspect I need to do something around matching record_IDs but any code fragments that you could post to assist me would be much appreciated.


Is it possible to do what I am trying. Can you assist?

Regards,
Gordon.

Vijay RautVijay Raut

Create one SControl to copy data as you want and then for a Button give content source as that created SControl.

You can get help on creating Scontrol in Ajax documentation.

splashgordonsplashgordon

I don't really want to do this as an S_Control as I need it to add to the fields and not just evaluate in the web browser.  We don't have Apex code.  Can this not just be done as "OnClick JavaScript" behind the button?  Would you be able to supply me a code snippet that would do this.  I am reasonably technically compentent so if you could just show me the way...

Thanks,

Gordon.

RickyGRickyG
Gordon -

First of all, my standard scolding.  No, you don't want to copy data.  What if the data changes in the place you copied it from, or the place you copied it to, or both?  And since there is a relationship between the two objects, you can always access the original data in reports and such.  So don't do it.

Assuming you ignore this advice, how about using workflow to update the fields in the Signoff object?  You can have some type of checkbox that the workflow will check before it does the copy, so the action of clicking the pushbutton is replaced by the action of checking the box. 

Hope this helps.

splashgordonsplashgordon

Thanks RickyG and thanks for the scolding.  Actually, copying data is exactly what we want to do.  If the data source subsequently changes it would be wrong for us to also change it in the target location.  Due to the business process being supported by these two objects, the source data for certain fields comes from the related delivery project record and should be available to be copied in the Signoff record when it is created.  There can be multiple signoff records per delivery project.

The point at which these fields should be filled in is when I am creating the signoff record in edit mode.  At that point it seems to me to make most sense to have a button the user can press.  The button can only be available in edit mode and, given the record goes through an approval process, I can lock the record once it has been submitted (i.e. the button can't get pressed again).  I could do this with field updates on a workflow rule but this isn't so obvious to the user as it happens "behind the scenes".  A button requires a positive action on the part of the user.

So, back to my original question, is it possible to have a button to do this and could someone show me some example JavaScript that I could adapt?

Regards,

Gordon.