Clone for tables

edited June 26, 2020 in Ideas
It would be great to be able to add a record level "clone" button to a table
0
0 votes

Implemented · Last Updated

Comments

  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    If a salesforce object supports the Clone action, you can get to the Clone screen through a "Redirect"-type Row Action: /{{Id}}/e?clone=1
  • Anna WiersemaAnna Wiersema 🛠️ 
    edited December 13, 2019
    You're asking if you can have a button on for each row of a table that would clone that row? I believe that you can do this with a redirect row action. Make the Redirect URL: /{{Id}}/e?clone=1
  • edited June 26, 2020
    Zack and Anna, That will clone the record... but i end up on the individual record view and i want to remain on the table view and just have the new record appear in the table. I looked to change the object's "clone" template in the salesforce "object" page.. but it only allows individual record templates in the drop down where you pick which template to use.
  • edited December 18, 2014
    Was anyone ever able to help with this?  I'd really like to figure this out as well...
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    Here is a Snippet that can be used as a Row Action in a Table to clone that row inline in the table.

    Add this as the Resource Body of a new JavaScript Resource of type "Inline (Snippet)", named "CloneRecord":
    var params = arguments[0],
        item = params.item,
        row = item.row,
        model = params.model,
        $ = skuid.$;
        
    var ADDITIONAL_FIELDS_NOT_TO_CLONE = {
        'TotalPrice':1,
        'Id':1,
        'attributes':1
    }; 
    // Create a new row in our table
    var newRow = model.createRow(),
        rowUpdates = {};
    // Put in default values from the fields in our current row
    if (row) {
        $.each(row,function(fieldId,val) {
            // Only allow fields that are Objects,
            // or that are Createable
            if ((val !== null) && !(fieldId in ADDITIONAL_FIELDS_NOT_TO_CLONE)) {
                var modelField = model.getField(fieldId);
                if ((typeof val === 'object') 
                || (modelField && modelField.createable)) {
                    rowUpdates[fieldId]=val;
                }
            }
        });
    }
    model.updateRow(newRow,rowUpdates,{initiatorId:item._GUID});
    // Force all registered lists to put our row into edit mode
    $.each(model.registeredLists,function(){
        // See if this item has been rendered in this list yet
        var newItem = this.renderedItems[newRow.Id];
        if (newItem) {
            newItem.mode = 'edit';
            newItem.refreshFields();
        }
    });

    image

    And then add a Row Action to any Table in the page you have this Snippet included in, that is of type "Custom (Run Snippet)" and put "CloneRecord" as the Snippet name.

    image



  • edited December 18, 2014
    Thanks Zach... I tried this a few different ways, but I can't seem to get it to work.
    I did exactly as you said... created a new inline snippet and added a row action to the table.  When I click the row action, a new row is created, but none of the data is copied to the new record.  Also, when the action is finished, the page is redirected to a new page...

    image

    image

    I'm not certain that it matters, but my table is in a popup and is comprised of Template fields.  All of the data is from the model though...
  • edited October 1, 2015
    How do I input this code? Forgive my ignorance but I do not know coding
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited December 21, 2016
    Hi Vanessa, that's okay, no worries! Here's how to do it: go to this tutorial and scroll down to Step 5: Click to Add a Row Action . Do steps 5 and 6, where you'll be adding a row action of type "Redirect", describe in 6-B. For "URL", instead of using /{{Id}} as it shows in the tutorial, put /{{Id}}/e?clone=1
  • edited October 1, 2015
    Thanks Zach, could you use the long coding below that you posted about a year ago to clone hundreds of rows at once rather than individually (one at a time)? Or how would I go about that?

  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited December 21, 2016
    Yes, you could do something like that --- a slightly modified version of the code shown below would accomplish that, as long as you didn't want to clone related records as well. What kinds of records are you trying to clone? For instance if you have a table of Contacts, and you used the snippet below, it would only clone the Contact, not any records related to each Contact. What does your clone process look like?
  • edited October 1, 2015
    I am trying to mass clone products. Our process is to create a contract, then add the products in question and assign them to a particular individual. I want to try to be able to mass clone all of the previous different products already created so I don't have to add them again line by line.
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    This is now possible to do without any code at all using the Action Framework, using the "Create new row in Model" Action.

    1. Add a Row Action (or Mass Action, for mass-cloning!) to your Table.
    2. Action Type should be "Run Multiple Actions", Action Label should be "Clone" and Action Icon should be "sk-icon-clone"
    3. Click on the Actions property category.
    4. Click the + icon to add a new Action.
    5. Action Type should be "Create new row" - select the same Model as your Table's Model.
    6. Click the + icon on your Create new row action to add a Default Value to your new row. Do this for each field that you want to populate in your cloned row. The value should be {{{FieldName}}} where FieldName should be replaced with the name of each field, e.g. "{{{FirstName}}}", "{{{LastName}}}", "{{{My_Custom_Field__c}}}". Only do this for createable fields on your model --- for instance, don't try to clone Id, CreatedDate, LastModifiedById because this won't work and is not necessary.

    image

    image

    image

    And voila, here's what you get --- row-level and/or mass-action cloning!

    image

    image
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited December 21, 2016
    Vanessa, I posted another comment on this Conversation where I describe how to do what you're looking for without writing code (using the Action Framework). Hopefully my instructions are clear, and this helps you accomplish what you're looking for!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!