record\create and record\update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brotherlouie
    Junior Member
    • May 2023
    • 14

    #1

    record\create and record\update

    I have an entity named "Bilet" in a base plus property. I have a flight date (ucusTarihi) field in this entity. I also have another entity named Ucustarihi in the event property. With the record\create command, I trigger some fields in the ticket entity with a formula to create a new record in the flight date entity. My formula is below and it really works.

    record\create(
    'Ucustarihi',
    'name', name,
    'dateStart', ucusTarihi,
    'dateEnd', ucusTarihi,
    'biletId', id,
    'assignedUserId', assignedUserId,

    );

    When I update the record in my main entity 'Bilet', it creates a copy in the 'Ucustarihi' entity. I tried to solve this with create\update but I couldn't. Is there a way to do this?

    What I want to do is basically this; after creating a record in the main entity, a record is automatically created in the other entity. But I want to prevent it from creating a copy again unless I make a change in the main entity.

    If you can help me I would be very happy. Thank you in advance.
  • lazovic
    Super Moderator
    • Jan 2022
    • 968

    #2
    Hi brotherlouie,

    You can use an if condition using the entity\isNew() function. Example:
    Code:
    if (entity\isNew()) {
       record\create(
       'Ucustarihi',
       'name', name,
       'dateStart', ucusTarihi,
       'dateEnd', ucusTarihi,
       'biletId', id,
       'assignedUserId', assignedUserId
      );
    }

    Comment

    • brotherlouie
      Junior Member
      • May 2023
      • 14

      #3
      lazovic Thank you very much. It really worked. Apart from that, is it possible to update the flight date of the relevant record when I update the flight date?

      Comment

      • lazovic
        Super Moderator
        • Jan 2022
        • 968

        #4
        brotherlouie,

        You can try using something like this formula script:
        Code:
        if (entity\isAttributeChanged('flightDate') {
            record\update('Record', recordId, 'flightDate', flightDate)
        }

        Comment

        Working...