API Example: Simple record copy

Comments

16 comments

  • Avatar
    Bob Love

    Nick,

    Been working on a way do copy the record from the parent vs. the detail that would duplicate all the connected records along with the duplicated parent record.

    Have you tried that yet?

    0
    Comment actions Permalink
  • Avatar
    Nic

    Robert,

    I unfortunately haven't had the chance to expand on this since I first posted it -- have you had any luck in your attempts?

    0
    Comment actions Permalink
  • Avatar
    Bob Love

     Nick,

    Yes I have found a way.... it is fairly complex and not as easy would hope.... at least the way I have found... Could we email each other to talk more ?

    0
    Comment actions Permalink
  • Avatar
    Brad Stevens
    Hi Robert, can I suggest sharing it here and others might be able to help as well? I'm certainly interested in how to achieve this.
    0
    Comment actions Permalink
  • Avatar
    Nic

    Robert,

    You're free to post any findings here. If you have any specific questions I can help answer you can send an email to support@knackhq.com

    0
    Comment actions Permalink
  • Avatar
    Jeff Zearfoss

    Hi Nicolas,

    Sorry for asking in advance -- can I get a little more detail about how/where to insert the code? 

    Your newbie friend,

    Jeff

    0
    Comment actions Permalink
  • Avatar
    Mark Waschkowski

    Hi Nic,

    Just a quick clarification, what kind of field is field_31?

    field_31: data.field_31_raw


    Thanks,


    Mark

    0
    Comment actions Permalink
  • Avatar
    Nic

    field_31 would be any complex field, like an address field or a date / time field. _raw will give Knack all of the properties it needs to insert the right values where needed.

    0
    Comment actions Permalink
  • Avatar
    Mark Waschkowski

    OK, great, thanks!

    0
    Comment actions Permalink
  • Avatar
    Ericalderman

    Hi Nick,

    I'm having trouble with this.  It seems to be choking on this reference:

            field_72: data.field_72_raw[0].id

    This is a connection field, so following the inline instructions I'm using the "_raw[0].id" syntax.  But I'm getting an error in the JS console:


    VM2351:5 Uncaught TypeError: Cannot read property '0' of undefined


    If I remove this one field reference, the button works and I get a copied record -- but of course it's not connected to the right parent record.  


    Any ideas?


    0
    Comment actions Permalink
  • Avatar
    Mark Waschkowski

    Hi,

    Just do a check/set to a variable like so:

    if( data.field_72_raw &&  data.field_72_raw[0]){

      field_72 =  data.field_72_raw[0].id;

    }


    Cheers,


    Mark

    0
    Comment actions Permalink
  • Avatar
    Valerie

    Eric,

    Since it appears that your field_72 can sometimes be blank, including the check statement that Mark has written above should resolve this error. This will add a check to make sure that there is data within your field_72 and if so, it will be included as a field to copy.

    0
    Comment actions Permalink
  • Avatar
    Eric Alderman

    Mark, Valerie: thanks!

    0
    Comment actions Permalink
  • Avatar
    undefined undefined

    Hi, I am desperately looking for a similar solution to either copy multiple records or, as Bob mentioned, copy multiple records from a parent to a child object. Any ideas? Thank you

    0
    Comment actions Permalink
  • Avatar
    undefined undefined

    @Bob, if you can share your solution it would be much appreciated. I am happy to swap code :)  

    0
    Comment actions Permalink
  • Avatar
    Mark Waschkowski

    Hi Frederico,

    Just follow the example given but you would have to loop through multiple time to create multiple records. If you need professional help I can do the work for you, just write me: mark@appweaverz.com.

    Best

    Mark

    0
    Comment actions Permalink

Please sign in to leave a comment.