Create duplicate records automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Emmker
    Member
    • Nov 2023
    • 65

    Create duplicate records automatically

    I have an entity 'CLicense' with a field 'quantity'.
    I am trying to have a formula to autocrate 'quantity -1' extra duplicate records when I save the original record.

    Trying to use the while function:

    PHP Code:
    $n = quantity -1;
    $count = record\count(CLicense, "serial", serial);
    
    while($count < $n)    
    {record\create(CLicense, 'licenseType',licenseType, 'kind', kind, 'serial', serial)};
    I get error 500 when I am trying to save the original record.

    It is my first time with the while function and I am a bit lost here.
  • Emmker
    Member
    • Nov 2023
    • 65

    #2
    With a modification of a code that someone posted here (and was deleted) I did it with:

    PHP Code:
    $n = quantity - 1;
    $i = 0;
    
    while($i < $n)
    {
       record\create('CLicense',
                     'licenseType', licenseType,
                     'kind', kind,
                     'serial', serial);
       $i = $i + 1;
    };

    Comment


    • lazovic
      lazovic commented
      Editing a comment
      Sorry if I misled you. Proposed formula script was unfinished and I wanted to finish it and send you the correct one. However, I'm glad I could help you.
  • Emmker
    Member
    • Nov 2023
    • 65

    #3
    lazovic Was that you? Thank you.
    The unfinished one created endless records but I fixed that.
    Thanx again

    Comment

    Working...