record\create and record\update

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

    #16
    lazovic

    Could there be an error in the formula I used to create the record in the main entity? Because it does not update at all.

    The formula script I used is as follows;

    if (entity\isNew()) {
    record\create(
    'Ucustarihi',
    'name', name,
    'dateStart', ucusTarihi,
    'dateEnd', ucusTarihi,
    'biletId', id,
    'assignedUserId', assignedUserId
    );
    }



    if (entity\isAttributeChanged('ucusTarihi')) {
    record\update('Ucustarihi', ucustarihiId, 'dateStart', ucusTarihi, 'dateEnd', ucusTarihi);
    }


    Also thank you for your patience and helpfulness.

    Comment

    • lazovic
      Super Moderator
      • Jan 2022
      • 979

      #17
      brotherlouie,

      The formula script for creating the entity looks fine, and if there were problems with it, the record would not be created at all.

      Can you please zip up folder {ESPO_DIR}/custom/Espo/Custom and send it so that I can reproduce the situation in my environment and help you create a correct formula script? Please note that this folder does not contain any personal data, only the entities structure. You can send it in private messages.

      Comment

      • lazovic
        Super Moderator
        • Jan 2022
        • 979

        #18
        brotherlouie,

        Please use the following formula script:
        Code:
        if (entity\isNew()) {
            $ucustarihiId = record\create('Ucustarihi',
            'name', name,
            'dateStart', string\concatenate(ucusTarihi, ' 00:00:00'),
            'dateEnd', string\concatenate(ucusTarihi, ' 00:00:00'),
            'assignedUserId', assignedUserId    
            );
            ucustarihiId = $ucustarihiId;
        }
        
        if (entity\isAttributeChanged('ucusTarihi')) {
            record\update('Ucustarihi', ucustarihiId,
                'dateStart', string\concatenate(ucusTarihi, ' 00:00:00'),
                'dateEnd', string\concatenate(ucusTarihi, ' 00:00:00'))
        }
        The thing is that simply assigning a biletId to created record Ucustarihi won't work, because Ucustarihi can contain multiple bilets (array). So in this case we assign the created record Ucustarihi to record Bilet directly.

        Also, there was a problem with the setup dateStart and dateEnd field values for Ucustarihi. These fields accept date-time values, not only date. This was also changed.

        I look forward to your feedback.

        Comment

        • brotherlouie
          Junior Member
          • May 2023
          • 22

          #19
          lazovic

          Thank you very much. It works great. I took your valuable time because of my missing information. And thank you again for helping me to get new information about Espo.

          Comment


          • lazovic
            lazovic commented
            Editing a comment
            Glad everything works for you.
        • brotherlouie
          Junior Member
          • May 2023
          • 22

          #20
          Hello, I need your experience and knowledge. Can you support me if possible? I am using the formula you created last. I really got rid of a big problem. However, I am experiencing an interesting situation.

          I have an enum field named 'ucusdetay' in my 'bilet' main entity. I created an enum field named 'islemdetay' in my 'Ucustarihi' sub entity.

          When creating a record in my 'bilet' entity, a record is created without any problems in my sub entity.

          However, when I update only the 'ucusdetay' enum field in the main entity, it does not work.

          The strange thing is; when I change both my 'ucusdetay' enum field and my 'ucusTarihi' field, both fields in my sub entity are updated correctly.

          What I am trying to do is to update only when I change any of the fields.

          Can you help?


          My formula script is as follows;

          if (entity\isNew()) {
          $ucustarihiId = record\create('Ucustarihi',
          'name', name,
          'ucusdetay', islemdetay,
          'dateStart', string\concatenate(ucusTarihi, ' 00:00:00'),
          'dateEnd', string\concatenate(ucusTarihi, ' 00:00:00'),
          'assignedUserId', assignedUserId
          );
          ucustarihiId = $ucustarihiId;
          }

          if (entity\isAttributeChanged('ucusTarihi')) {
          record\update('Ucustarihi', ucustarihiId,
          'ucusdetay', islemdetay,
          'dateStart', string\concatenate(ucusTarihi, ' 00:00:00'),
          'dateEnd', string\concatenate(ucusTarihi, ' 00:00:00'))
          }​

          Comment

          Working...