Announcement

Collapse
No announcement yet.

Possible to reset increment number by formula

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

  • Possible to reset increment number by formula

    Hello, as the subject says: Is it possible to reset the next number in number field by formula?

  • #2
    Try to do it with the "Advanced" pack using a workflow

    Comment


    • shalmaxb
      shalmaxb commented
      Editing a comment
      I do not have advanced pack

  • #3
    shalmaxb,

    Please describe your purpose. Perhaps, under certain conditions of record creation, the field with the type Number (auto-increment), or maybe the field with the type Auto-increment remained empty?

    Comment


    • #4
      I have an entity, where records from another entity are displayed in a 1:n relationship. The number of these records may vary (maybe 10 records or 100....).
      I want to number theses records, always beginning with 1 and ending with the last number depending on the amount. If I use one of the auto-increment fields in the related entity, it numbers the first group of records for example 1 to 10, but the second record group would be 11 to n. I want this second group starting again from 1.
      I tried with a workaround: When the first group of records had been auto-incremented 1 to 10, I copied these values into another field (normal integer) and made it non-editable by condition, so it would not be affected, if the auto-increment would be reset. In this case, I would not disply the auto-increment, but only the second integer field, so the user would only see theses copied values, the auto-increment would work in the background.
      So I thought, if it would be possible to reset the auto increment on creating a new group of records, to make it start with 1 again, copies these new values to the second field and would be resetted again on creating a new record an so on.

      So I am looking for a formula that says: if record create, reset next number to 1.

      Comment


      • #5
        Formula :

        Entity = NextNumber
        EntityType = your entity with auto-increment field
        fieldName = your auto-increment field Name

        first find the entity with formula :
        $id = record\findOne('NextNumber', 'entityType', 'desc', 'entityType=', 'yourEntityType')

        then update :

        record\update('NextNumber', $id, 'value', 1)


        you can too do :

        $value = record\attribute('NextNumber', $id, 'value')
        if $value > 10 then set value = 1 // of course by formula.

        Comment


        • shalmaxb
          shalmaxb commented
          Editing a comment
          item, thanks. Is there such entity named NextNumber?

        • item
          item commented
          Editing a comment
          Yes,
          Is there all auto increment are store

          Use too fieldName= … in entity\FindOne(.. for better

      • #6
        unfortunately does not work. it seems, that NextNumber does not react at all to formula.

        Comment


      • #7
        entityName = Exemplare
        increment-field = ex

        So I want to create one record in Exemplare, which should get the number 1, then another one, which should get the number 2 and so on.

        These records link 1:n to another entity, where it appears as two (or more) items in a list with the numbers.

        In that entity again I want to create another record, which should have linked records from the first entity, but not the same as for record 1, but new linked records, which can be more for example, record 1, record 2, record 3... These records should be numbered again from 1 to n.

        As it is now, the numbers are sequencial, what means, they start for the first two by 1 and go to 2, for the second from 3 to n.

        The auto-increment field applies numbers from 1 to n independently of the number of records in the related (second) entity.

        Comment


        • item
          item commented
          Editing a comment
          Haaaa ok...
          so i understand so :
          EntityX 1:n Exemplare

          recordAEntityX : Exemplare->ex => 1 to 10
          recordBEntityX : Exemplare->ex => 1 to 10
          and so..
          of course in these case, auto-increment number will fail.
          i see 2 solution.
          when create recordA .. then directly create 10 record Exemplare and then set value nextNumber to 1

          or second solution without auto-increment but with findRelatedOne :

          $id = record\findRelatedOne('ParentEntity???', ID???, 'exemplares', 'ex', 'desc')
          $maxValue = record\attribute('Exemplare', $id, 'ex');
          ifThen($maxValue >= 10,
          $maxValue = 0;
          )

          ex = $maxValue + 1;

          i think

        • shalmaxb
          shalmaxb commented
          Editing a comment
          I already tried a lot in that direction, I will see tomorrow, if I can construct anything from your proposal. It is really nice, to see your engagement for my problem. Thanks a lot.
          The only thing I need is, that I want to get the number of the items filled in automatically. It is not a big thing to do that manually, if there are 10 items, but when I have 100 items, it would be very tedious work.

      • #8
        strange, for me test on demo.. all work as expected. maybe you talk another type of auto-increment.

        $id = record\findOne('NextNumber', 'entityType', 'asc', 'entityType=', 'Account', 'fieldName', 'number');
        output\print($id);
        $value = record\attribute('NextNumber', $id, 'value');
        output\printLine($value);
        $result = record\update('NextNumber', $id, 'value', 10);
        $value = record\attribute('NextNumber', $id, 'value');
        output\printLine($value);​

        Comment


        • #9
          I tried it with my entity and my auto-increment-field, result see screenshot. I guess I still am doing something wrong......

          Click image for larger version

Name:	auto-increment.jpg
Views:	320
Size:	45.3 KB
ID:	95810

          Comment


          • #10
            I think i understand,
            you have "database" auto-increment type of field.
            this kind of field, must be unique ! it's nomarly primary key index (and ??). You can not have duplicate number.
            these kind of field is under "database control", no "application" (i explain so with my english)
            see print-screen, i just print-screen from demo

            Comment


            • #11
              I understand that the same way. Because of that fact, that you cannot have duplicate numbers, I wanted to reset it. Before that I would have copied the first emitted numbers to another field (integer) to preserve the values. This second copy-field I would have made non editable after copying and reset the auto-increment.
              Then for the second set of related records the auto-increment would start from one again, the numbers would be copied again and so on. But this also did not work. Does not seem to be possible.

              I do not need necessarily an auto-increment field, because I think I could sequence the numbers also by formula. That I see in your last proposal as well. I will see tomorrow, if I get any solution on basis of this.

              Comment

              Working...
              X