record\create and record\update

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

    #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
    • 970

    #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
      • 16

      #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
        • 970

        #4
        brotherlouie,

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

        Comment

        • brotherlouie
          Junior Member
          • May 2023
          • 16

          #5
          If I know the id of the entity I created, this formula works. But since I automatically create a record for another entity from the main entity, the id is created in my other entity and I need to query it from the main entity to update it. I think I won't be able to do this. So I will create a single record. And if an update is needed, I will do it manually from the other entity. Thank you for your support.

          Comment

          • lazovic
            Super Moderator
            • Jan 2022
            • 970

            #6
            brotherlouie,

            You can access the ID of any record in the system, regardless of where the formula script is called from.

            If you tell me specifically which record you want to access from the main entity and which entity can connect them, I will try to help you. It will also be useful to look at their relationships (One-to-Many, Many-to-Many, etc.).

            Comment

            • brotherlouie
              Junior Member
              • May 2023
              • 16

              #7
              The entity I want to reach is 'Ucustarihi'.
              My main entity is 'ticket'.
              There is a many to one relationship between my main entity 'ticket' and 'Ucustarihi'.
              When I make a record in the main entity with the formula you gave, a record is created in my 'Ucustarihi' entity. What I want to do is update the relevant record in the 'Ucustarihi' entity when I make a change in the record in the main entity. The only record fields to be updated here are;

              'dateStart', uçusTarihi,

              I am grateful for your help with my problem. Thank you for your time.

              Comment

              Working...