Announcement

Collapse
No announcement yet.

Formula record\update not working

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

  • yuri
    commented on 's reply
    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.

  • yuri
    replied
    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.

    Leave a comment:


  • shalmaxb
    replied
    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.

    Leave a comment:


  • yuri
    replied
    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.

    Leave a comment:


  • esforim
    commented on 's reply
    Bug report it otherwise if you believe you confident can do a pull request on it.

  • shalmaxb
    replied
    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.

    Leave a comment:


  • Maximus
    replied
    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.

    Leave a comment:


  • shalmaxb
    replied
    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.

    Leave a comment:


  • Maximus
    replied
    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.

    Leave a comment:


  • shalmaxb
    replied
    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....

    Leave a comment:


  • eymen-elkum
    replied
    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.

    Leave a comment:


  • shalmaxb
    started a topic Formula record\update not working

    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.
Working...
X