Announcement

Collapse
No announcement yet.

Problem with Formula Function - record\findone

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

  • 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'nullnull'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.

  • #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.

    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.

  • #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.

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