Problem with Formula Function - record\findone

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murugappan
    Active Community Member
    • Aug 2017
    • 467

    Problem with Formula Function - record\findone

    Hi,

    This is my scenarion:

    (1) Define a many-to-one link between entity "Assured" and "PolicyPlan" called "PolicyPlan"
    (2) Defined a input field "assdpolicyNumber" in the "Assurd" entity.
    (3) Created a formula to update "policyPlanId" for the "PolicyPlan" link as follows (formula is in Before Save Custom Script)[PHP]:

    PHP Code:
    ifThen(assdPlantype != NULL,
    policyPlanId = record\findOne('PolicyPlan', null, null, 'name=', assdpolicyNumber)); 
    
    (4) When i insert a new record with a value set for "assdpolicyNumber", the links is updated correctly and the "name" of the for entity "PolicyPlan" shows correctly

    The problem areas:
    (5) When I edit the record and enter a new value for "assdpolicyNumber", the new link id inserted correctly but the field displays the ID value instead of the "name" field.
    (6) When i refresh the page, the "name' field now show correctly.

    Why does it not show the "name" field correctly at step 5 and requires a page refresh?
    Last edited by murugappan; 12-12-2023, 08:15 AM.
  • yuri
    Member
    • Mar 2014
    • 8444

    #2
    Try this code instead:

    Code:
    if (assdPlantype) {
        policyPlanId = record\findOne('PolicyPlan', null, null, 'name=', assdpolicyNumber);
    
        if (policyPlanId) {
            policyPlanName = record\attribute('PolicyPlan', policyPlanId, 'name');
        }
    }
    It will set the link name attribute (which is not-storable and has no effect on anything other that displayed data ).
    Last edited by yuri; 12-12-2023, 01:23 PM.
    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


    • murugappan
      murugappan commented
      Editing a comment
      yuri Hi,

      Thank you for the advice, The code could not be used as it looks like PHP Standard code. When i tried it, it was giving me syntax error. Its ok, i converted them to the function formula structure for Espocrm. It worked great. Thank you so much.
  • yuri
    Member
    • Mar 2014
    • 8444

    #3
    It was incorrect closing ')'. I fixed the code. This is not PHP, it's a valid formula-script as of a few versions back.
    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


    • murugappan
      murugappan commented
      Editing a comment
      yuri Thank you for the update and apology for the wrong assumption. I tested and working fine.
Working...