Announcement

Collapse
No announcement yet.

Formula record\update not working

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

  • Formula record\update not working

    Hello,
    I have two custom entitites connected by n:n relationship. Now I want to change a value in entity1, when a field in entity2 is true (both are boolean). My formula looks like this:

    Code:
    ifThen(
    bool2,
    record\update('entity1', 'Id1', 'bool1', false)
    );
    What means, that, if I tick bool2 in entity2, bool1 in entity1 should be unticked. But I do not get it to work, it happens nothing, also no error in log-file.

  • #2
    Hello,

    Are you sure the value of Id1 is catched correctly?
    Try to store it to some field like description and see if it is correct.
    CEO of Eblasoft
    EspoCRM Expert since 2014
    Full Stack Web Developer since 2008
    Creator of Numerous Successful Extensions & Projects​

    Comment


    • #3
      I created a textfield to show the ID and in entity2 the correct ID shows up. In entity1 it does not. I do not find the required Id, nothing in the formula dropdown....

      Comment


      • #4
        Hi,
        1. I might be wrong but 'entity1' looks wrong as well. Do you really called entity like 'entity1' or it's just the relation link name of this entity?
        Normally the entity name should look like: 'Account', 'Contact', 'Team', 'Opportunity' etc. https://docs.espocrm.com/administrat.../#recordupdate

        2. As eymen mentioned Instead of 'Id1' should be something like '234effw3324fs'.
        If you have a link type connection to entity1, you can set something like: entity1id.
        In case you have a multiple type link with the entity 'entity1', you can try to do it via a variable that needs a more tricky way obviously.

        Comment


        • #5
          Maximus , thank you for looking into this. The names in my example are only placeholders, my entitiy actuall has a working name. For the ID I use the ID provided by the dropdown in formula, where this ID is a in other formulas working relationship name.

          Is there any instruction on how to use variables? So far I did not find any. I am not a programer at all and have to guess a lot and coming to conclusions by (my) logic and trial/error based on the sometimes little information.

          Comment


          • #6
            Here is a description of how you can define a variable within Formula https://docs.espocrm.com/administrat...ula/#variables.
            Variable is very useful if you need to store there some static temporary value or store there a result of some calculation, or a dynamic search result, etc. After you can use this variable in the functions of Formula.

            Comment


            • #7
              I remembered, that I had that problem before and it was solved. esforim fortunately added it to the espoCRM learn and design wiki, where I found it:

              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


              According to that (working) solution, the documentation of record\update is not quite right, as the related ID should not be in quotes. The documentation example puts the ID in quotes.

              Comment


              • esforim
                esforim commented
                Editing a comment
                Bug report it otherwise if you believe you confident can do a pull request on it.

            • #8
              Documentation is right. Formula usage requires some knowledge in programming. It may be difficult to understand the principle how functions work without experience in programming.

              Comment


              • #9
                yuri

                This is from another thread, post 7:

                https://forum.espocrm.com/forum/gene...tity#post64754 (last sentence of paragraph 2.2, written by Maximus).

                This is from documentation (obs. the example, where ID is in quotes):



                In my case, the formula actually worked only with ID without quotes. The usage of formula is something, I actually get quite well done, even I am not a programer.

                Comment


                • yuri
                  yuri commented
                  Editing a comment
                  See my post below.

                  When you write id it means you use an entity attribute 'id'. When you write quoted 'some-long-id' it mean you use a scalar value.

              • #10
                Functions accept expressions as arguments. It's not correct to say that a function requires quoted ID or anything like that.



                Code:
                someFunction(EXPRESSION1, EXPRESSION2);

                EXPRESSION1 can be:

                * scalar value
                * variable
                * attribute (this one is where Formula differs from other programming languages, it's a special lexeme for accessing values of a current entity)
                * combination of all those forming an expression


                Scalar STRING as an argument:

                Code:
                someFunction('some string');

                Scalar INT as an argument:

                Code:
                someFunction(10);

                Scalar FLOAT as an argument:

                Code:
                someFunction(10.5);

                Scalar BOOLEAN as an argument:

                Code:
                someFunction(true);

                NULL value as an argument:

                Code:
                someFunction(null);

                Expression as an argument:

                Code:
                someFunction(2 + 2);

                Expression as an argument:

                Code:
                someFunction(anotherFunction());

                Variable as an argument:
                ​​​​​​​
                Code:
                someFunction($someVariable);

                Attribute as an argument:
                ​​​​​​​
                Code:
                someFunction(attributeName);

                The attribute lexeme was introduced to be able to write simple like this:

                Code:
                description = 'test';
                ​​​​​​​
                If we didn't have attributes we would need to write more verbose:

                Code:
                entity\setAttribute('description', 'test');
                Last edited by yuri; 03-24-2021, 12:41 PM.

                Comment

                Working...
                X