entity\clearAttribute(ATTRIBUTE) - Formula function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Davide Alghi
    Junior Member
    • Sep 2024
    • 12

    #1

    entity\clearAttribute(ATTRIBUTE) - Formula function

    Hi all,
    I'm trying to understand the logic of function entity\clearAttribute(ATTRIBUTE) in Formula (Before Save Custom Script).

    I tried to empty the industry field of the Account entity type.

    With
    Code:
    industry = '';
    or
    Code:
    entity\setAttribute('industry', '');
    it works: the field industry is emptied.

    But if I use entity\clearAttribute('industry') the field industry is unchanged.

    Analyzing the implementation code of entity\clearAttribute(ATTRIBUTE), I see that it is like an PHP array unset() (valuesContainer), so I understand why it does not empty the industry field.

    I'm trying to understand the logic of the function: maybe to prevent the user from modifying a specific field?

    BR
  • yuri
    Member
    • Mar 2014
    • 8940

    #2
    Hi,

    It unsets an attribute. It just removes the value from the memory (from the entity object). A cleared attribute is not synced with database. It does not set the attribute to null.

    It was a replicate of the internal clear method. Often used before serving values to a user to hide unwanted fields. Better never use it in formula.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • yuri
      Member
      • Mar 2014
      • 8940

      #3
      Empty strings are rarely used in Espo. Use null instead.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • Davide Alghi
        Junior Member
        • Sep 2024
        • 12

        #4
        Hi Yuri, tnx.

        this clarify my question

        Originally posted by yuri

        It was a replicate of the internal clear method. Often used before serving values to a user to hide unwanted fields. Better never use it in formula.

        Comment

        Working...