Announcement

Collapse
No announcement yet.

Change the value of one entity field when changing a value in another entity

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

  • Change the value of one entity field when changing a value in another entity

    Hi, as the title says, I want to change the value of one entity field in a second entity (bool), when I change a certain entity field (also bool) in the first entity. I already tried with record\update, but did not get it to work.
    My formula so far (where entity1 is the first entity, IDrelated1 the related record by one-to-one relationship, field1 the field I will change, value1 the value), entity2 the second entity etc.). I would use an ifThen formula:

    Code:
    ifThen(
          field1 == true;
          record\update('entity1', 'IDrelated1', 'field1',  false
    );

  • #2
    Hi,
    Please investigate my example below:
    Code:
    ifThen(
        checkReady,
        record\update('Account', accountId, 'boolean', '0')
    )

    Comment


    • #3
      Hi, Maximus , thank you, but I don´t get it yet. checkReady does not have any attribute?

      Comment


      • eymen-elkum
        eymen-elkum commented
        Editing a comment
        You can replace checkReady by field1 or any boolean field, was just an example

    • #4
      Hi, eymen-elkum , thank you, that helped to understand better, how it works. The formula seems to work. But something strange happened. It worked for some minutes and when I appended another function to the same formula, it stopped working. So I deleted the other function to have the working formula again, but from that point on it did not work anymore. I tried every variation possible, but nothing.
      I am quite clueless now.

      Comment


      • eymen-elkum
        eymen-elkum commented
        Editing a comment
        Make sure to not forgot the semicolon at the end of every statement !!

        In the above example you have to put it after the )

        ifThen(
        checkReady,
        record\update('Account', accountId, 'boolean', '0')
        );

    • #5
      I don*t know, the syntax seems to be right, but I get an error message in the log (though, I don't know, if that has to do with my problem).

      [
      PHP Code:
      2020-11-19 06:52:39] Espo.WARNING: E_WARNING: rename(data\tmp\tmp8013.tmp,data\cache\application\classmapServices.php): Zugriff verweigert (code: 5) {"code":2,"message":"rename(data\\tmp\\tmp8013.tmp,data\\cache\\application\\classmapServices.php): Zugriff verweigert (code: 5)","file":"G:\\laragon\\www\\Werkverzeichnis\\application\\Espo\\Core\\Utils\\File\\Manager.php","line":308,"context":{"path":"data\\cache\\application\\classmapServices.php","data":"<?php\nreturn [\n  'ActionHistoryRecord' => 'Espo\\\\Services\\\\ActionHistoryRecord',\n  'AdminNotifications' => 'Espo\\\\Services\\\\AdminNotifications',\n  'App' => 'Espo\\\\Services\\\\App',\n  'Attachment' => 'Espo\\\\Services\\\\Attachment',\n  'AuthLogRecord' => 'Espo\\\\Services\\\\AuthLogRecord',\n  'AuthToken' => 'Espo\\\\Services\\\\AuthToken',\n  'CurrencyRate' => 'Espo\\\\Services\\\\CurrencyRate',\n  'DashboardTemplate' => 'Espo\\\\Services\\\\DashboardTemplate',\n  'DataPrivacy' => 'Espo\\\\Services\\\\DataPrivacy',\n  'Email' => 'Espo\\\\Services\\\\Email',\n  'EmailAccount' => 'Espo\\\\Services\\\\EmailAccount',\n  'EmailAddress' => 'Espo\\\\Services\\\\EmailAddress',\n  'EmailFilter' => 'Espo\\\\Services\\\\EmailFilter',\n  'EmailFolder' => 'Espo\\\\Services\\\\EmailFolder',\n  'EmailNotification' => 'Espo\\\\Services\\\\EmailNotification',\n  'EmailTemplate' => 'Espo\\\\Services\\\\EmailTemplate',\n  'EmailTemplateCategory' => 'Espo\\\\Services\\\\EmailTemplateCategory',\n  'ExternalAccount' => 'Espo\\\\Services\\\\ExternalAccount',\n  'GlobalSearch' => 'Espo\\\\Services\\\\GlobalSearch',\n  'Import' => 'Espo\\\\Services\\\\Import',\n  'InboundEmail' => 'Espo\\\\Services\\\\InboundEmail',\n  'Job' => 'Espo\\\\Services\\\\Job',\n  'Language' => 'Espo\\\\Services\\\\Language',\n  'LastViewed' => 'Espo\\\\Services\\\\LastViewed',\n  'Layout' => 'Espo\\\\Services\\\\Layout',\n  'LeadCapture' => 'Espo\\\\Services\\\\LeadCapture',\n  'LeadCaptureLogRecord' => 'Espo\\\\Services\\\\LeadCaptureLogRecord',\n  'Metadata' => 'Espo\\\\Services\\\\Metadata',\n  'MysqlCharacter' => 'Espo\\\\Services\\\\MysqlCharacter',\n  'Note' => 'Espo\\\\Services\\\\Note',\n  'Notification' => 'Espo\\\\Services\\\\Notification',\n  'Pdf' => 'Espo\\\\Services\\\\Pdf',\n  'Portal' => 'Espo\\\\Services\\\\Portal',\n  'PortalRole' => 'Espo\\\\Services\\\\PortalRole',\n  'Record' => 'Espo\\\\Services\\\\Record',\n  'RecordTree' => 'Espo\\\\Services\\\\RecordTree',\n  'Role' => 'Espo\\\\Services\\\\Role',\n  'ScheduledJob' => 'Espo\\\\Services\\\\ScheduledJob',\n  'Settings' => 'Espo\\\\Services\\\\Settings',\n  'Stream' => 'Espo\\\\Services\\\\Stream',\n  'Team' => 'Espo\\\\Services\\\\Team',\n  'User' => 'Espo\\\\Services\\\\User',\n  'UserSecurity' => 'Espo\\\\Services\\\\UserSecurity',\n  'Webhook' => 'Espo\\\\Services\\\\Webhook',\n  'Account' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Account',\n  'Activities' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Activities',\n  'Call' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Call',\n  'Campaign' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Campaign',\n  'CampaignLogRecord' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\CampaignLogRecord',\n  'CampaignTrackingUrl' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\CampaignTrackingUrl',\n  'Case' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\CaseObj',\n  'Contact' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Contact',\n  'Document' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Document',\n  'DocumentFolder' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\DocumentFolder',\n  'KnowledgeBaseArticle' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\KnowledgeBaseArticle',\n  'KnowledgeBaseCategory' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\KnowledgeBaseCategory',\n  'Lead' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Lead',\n  'MassEmail' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\MassEmail',\n  'Meeting' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Meeting',\n  'Opportunity' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Opportunity',\n  'Target' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Target',\n  'TargetList' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\TargetList',\n  'Task' => 'Espo\\\\Modules\\\\Crm\\\\Services\\\\Task',\n  'ArtCollectionWorks' => 'Espo\\\\Custom\\\\Services\\\\ArtCollectionWorks',\n  'Ausstellungen' => 'Espo\\\\Custom\\\\Services\\\\Ausstellungen',\n  'Dienstleister' => 'Espo\\\\Custom\\\\Services\\\\Dienstleister',\n  'Publikationen' => 'Espo\\\\Custom\\\\Services\\\\Publikationen',\n  'Rechnung' => 'Espo\\\\Custom\\\\Services\\\\Rechnung',\n  'RechnungGalerieverkauf' => 'Espo\\\\Custom\\\\Services\\\\RechnungGalerieverkauf',\n  'Vermietung' => 'Espo\\\\Custom\\\\Services\\\\Vermietung',\n  'Versand' => 'Espo\\\\Custom\\\\Services\\\\Versand'\n];\n","tmpDir":"data/tmp","tmpPath":"data\\tmp\\tmp8013.tmp","h":"[unknown(resource (closed))]"}} []

      Comment


      • eymen-elkum
        eymen-elkum commented
        Editing a comment
        There is no error here, just warnings, better to paste your formula here

    • #6
      Ok, here is my formula:

      Code:
      ifThen(
      kaufVorAblaufPos1,
      record\update('ArtCollectionWorks', 'vermietungWerke1', 'verleih', '0');
      record\update('ArtCollectionWorks', 'vermietungWerke1',
      'verkaufAbAtelier', '1')
      );
      and explanation:

      Click image for larger version

Name:	update_field.jpg
Views:	656
Size:	60.0 KB
ID:	64749

      Comment


      • #7
        Hi,
        I just want to shed a little bit more light on your screenshot:
        1. 'ArtCollectionWorks' is the entity name that you want to change
        2. 'vermietungWerke1' should be an ID of the Target entity, but:
        2.1. If you putting id in the quote, then you should put the strict ID (e.g. '5fa3eeea29a2bf77f'). So 'vermietungWerke1' won't work.
        2.2. The relationship that you have allows you to insert the ID field that will automatically determine a proper ID. For this, you just need to put this field key instead of 'vermietungWerke1' (I believe it something like: vermietungWerke1Id). Note, the field key name should be without quotes as it shown in my example above (e.g. accountId).

        Comment


        • #8
          Hi,
          I am still trying without success.

          The formula works, when I put the real ID key (the number/letter hash) into the formula, AND with quotes. If I put without quotes, I get this error:
          Code:
          Formula failed: function: record\update, index: 2, should be: string
          As soon as I put (in my case) vermietungWerke1Id into the target ID place, it won't work. I tried every possible combination, but it only works with the absolute Id (the hash), which for my purpose does not make sense.

          Comment


          • #9
            > As soon as I put (in my case) vermietungWerke1Id into the target ID place, it won't work. I tried every possible combination, but it only works with the absolute Id (the hash), which for my purpose does not make sense.

            I just presumed that the proper key name of the needed field is `vermietungWerke1Id`. To find the correct one please press Attributes button and find the desired ID field in the list.

            Comment


            • #10
              Hi,
              I finally got it to work. I deleted all relationships and recreated them. After that it worked. Here is the final formula (perhaps might help anybody with a similar problem):

              Code:
              ifThen(
              kaufVorAblaufPos1,
              record\update('ArtCollectionWorks', werkeVermietung1Id,
              'verleih', false);
              record\update('ArtCollectionWorks', werkeVermietung1Id,
              'verkaufAbAtelier', true)
              );
              The target record ID in fact has to be WITHOUT quotes (as Maximus indicated). The operators for the target boolean in my case worked as false/true.

              My thanks go to Maximus (I begin to understand the avatar name​​​​​​​) and the alway helpful and friendly eymen-elkum

              Comment

              Working...
              X