Announcement

Collapse
No announcement yet.

How to get original record id of cloned object?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get original record id of cloned object?

    Is there a way to get the id of the duplicated record in the workflow?
    Last edited by romach; 04-14-2023, 08:47 PM.

  • #2
    Hi romach,

    Can you please tell what you mean by the cloning? How is this cloning done? Maybe you mean duplicating?
    Please provide a little more detail and screenshots so that we can help you more quickly and efficiently.

    Comment


    • romach
      romach commented
      Editing a comment
      Hi, yes, I mean duplicating. I need the id of the record that was duplicated in order to use it in the workflow.

  • #3
    So the only way is to store the `id` in an extra field when the object is created. If you are duplicating an object, this field is not empty and can be used in a workflow.

    Comment


    • #4
      How to get duplicate contact ID instead of original contact ID in our created contact by Duplicate function:
      • Create a field with type Boolean for the required Entity (in my example it is Contact).
      Click image for larger version  Name:	1.png Views:	0 Size:	33.6 KB ID:	91272
      • Create a Varchar field for the same Entity with option Read-only.
      Click image for larger version  Name:	2.png Views:	0 Size:	30.0 KB ID:	91275
      • In Administration -> Entity Manager -> Contact -> Formula insert the formula:
        Code:
        	ifThen(
        	entity\isNew() == true && thisIsADuplicateBoolean == true,
        	thisIsADuplicateVarchar = id
        	);​

      Now, at the time of duplicating a Contact, check the thisIsADuplicateBoolean field and after creating a duplicate contact, get the Id in the thisIsADuplicateVarchar field.
      Click image for larger version  Name:	4.png Views:	0 Size:	129.4 KB ID:	91274




      Also, if desired, you can make thisIsADuplicateBooleanRead-only after creating a duplicate.
      Click image for larger version  Name:	5.png Views:	0 Size:	67.8 KB ID:	91276
      Last edited by victor; 04-21-2023, 02:28 PM.

      Comment


      • esforim
        esforim commented
        Editing a comment
        Quite a genius move! I read the formula and I can see it but I don't get the logic in the code.

    • #5
      Quite a genius move! I read the formula and I can see it but I don't get the logic in the code.
      - It looks like I didn't quite understand topic starter, and apparently he wants to have the ID of the original contact in one of the fields of the duplicate contact that was created by Duplicate function (I have no ideas for this case yet).
      - In my previous post the solution how to get duplicate contact ID instead of original contact ID in our created contact by Duplicate function.​

      Comment


      • esforim
        esforim commented
        Editing a comment
        Sound like it not possible to get the original ID from reading your update?

    • #6
      romach, esforim,

      ID of the original contact in one of the fields of the duplicate contact that was created by Duplicate function:
      1. In Administration -> Entity Manager -> Contact -> Fields we create an originalId field with Varchar type.
      2. In Administration -> Entity Manager -> Contact -> Formula we create a fomula:
        Code:
        	ifThen(
        	entity\isNew() && originalId == null,
        	originalId = id
        	);
        	
        	ifThen(
        	entity\isNew() != true && originalId == null,
        	originalId = id
        	);
        	
        	ifThen(
        	entity\isNew() != true && originalId != id,
        	originalId = entity\attributeFetched('originalId')
        	);  ​
      3. We do the Recalculate Formula for the necessary (or better in general for all) contacts (as shown in the screenshot 1).
      How it works:
      • After we make Recalculate Formula​ for the required contacts (or after creating a new contact) originalId field will be filled in each of them. And at this stage, the originalId field is equal to id. (screenshot 2).
      • After we do Duplicate function, the duplicate contact will have the id of the original contact in the originalId field. In this way, we received contact B, which in the originalId field contains the value of the Id field of contact A.
      • If we want to duplicate contact B (in the originalId field, which still contains the value of the Id field of contact A) so that in the created contact C, the originalId field contains the Id of contact B, before Duplicate function​, we need to clear the originalId field in contact B.
      Attached Files
      Last edited by victor; 04-21-2023, 03:14 PM.

      Comment

      Working...
      X