Automatic link to relationship

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • anlugarb
    replied
    Hi, I have a similar situation. I created a field with reference to the "status (call)" field in the lead entity. I'm looking for a way to automatically update it when creating a call or scheduling a call, so that there can be a visible update in the label.

    Click image for larger version

Name:	image.png
Views:	61
Size:	40.2 KB
ID:	109729​*The numbers and personal data are fictitious, only for personalization testing purposes

    Leave a comment:


  • MyloStark
    replied
    You're a monster, that works too. THANK YOU!

    Leave a comment:


  • rabii
    replied
    Hey,

    sure here is how you can do it, change the test to the name of the field on the lead and also prova to the value you want to set for that field:

    PHP Code:
    //Update test field of the Lead (Parent) with the value prova
    ifThen(faseAcquisto == "Consegnato" && parentId,
    
       record\update('Lead', parentId, 'test', 'prova');
    );
    Hope this helps.

    Leave a comment:


  • MyloStark
    replied
    Can I still take advantage of your availability? the question is very similar, I have a text field in the Lead (parent), I would like to modify it when I update the "faseAcquisto" field of Contract. This is the Formula (in Contract):

    ifThen(faseAcquisto=="Consegnato",
    entity\setAttribute("parent.test","prova")
    );
    output\print(parent.test);​

    Because it does not work? But above all because the print is able to get to the parent field while the setAttribute is not?
    Last edited by MyloStark; 07-26-2023, 01:47 PM.

    Leave a comment:


  • MyloStark
    replied
    work this too, you're the top!

    Leave a comment:


  • rabii
    replied
    Ok fir the first question why the formulas don't work when you change their order is simply you have to add a semi colon to the end of the last formula, like below

    PHP Code:
    
    //Update Vendor Appointment
    ifThen(entity\isAttributeChanged('parentId') && parentId,
       $appointmentId = record\findOne('VendorAppointment', null, null, 'parentId=', parentId);
       ifThen($appointmentId, entity\setAttribute('appuntamentoVId', $appointmentId));
    )​​;
    
    //Create name ( you can simplify this code into one line like below)
    name = string\concatenate("Contratto ", entity\attribute('parent.name'));
    This should work fine. If you know how to code you can definitely do it but you need to be aware of how espocrm works and how you can add custom code.

    Leave a comment:


  • MyloStark
    replied
    I meant the formulas //Create name and //Update Vendor Appointment.
    "to create a custom view for your link and send a request to an api endpoint to recover data and change it." I see it a complicated thing? Is it feasible for someone like me who couldn't even do the previous formula? ?​

    Leave a comment:


  • rabii
    replied
    what do you mean by reverse the order of the 2 formulas ?

    Yes the result will appear only after the page is refreshed. if you want instant changes formula is not the way, you will have to create a custom view for your link and send a request to an api endpoint to recover data and change it.

    Leave a comment:


  • MyloStark
    replied
    ​hello, IT WORKS but the update only takes place or is visible only when I reload the page. In Formula, I currently have this:

    //Create name
    $nameContract= entity\attribute("parent.name");
    $newName = string\concatenate("Contratto ", $nameContract);
    name = $newName;
    //Update Vendor Appointment
    ifThen(entity\isAttributeChanged('parentId') && parentId,
    $appointmentId = record\findOne('VendorAppointment', null, null, 'parentId=', parentId);
    ifThen($appointmentId, entity\setAttribute('appuntamentoVId', $appointmentId));
    )​

    if it can be useful I noticed that if I try to reverse the order of the 2 formulas both don't work.
    - Cache emptied​
    - I tried in both Before Save Script and API
    Last edited by MyloStark; 07-26-2023, 11:00 AM.

    Leave a comment:


  • rabii
    commented on 's reply
    you are welcome

  • MyloStark
    replied
    as soon as I can try and update, in the meantime, thanks!

    Leave a comment:


  • rabii
    replied
    Here is a formula that could do the job, this formula should be used in Contract formula entity, also please change the name of the fields and entities based on the correct ones in your instance:

    PHP Code:
    ifThen(entity\isAttributeChanged('parentLeadId') && parentLeadId,
    
    $appointmentId = record\findOne('Appointment', null, null, 'leadId=', parentLeadId);
    
        ifThen($appointmentId, entity\setAttribute('appointmentId', $appointmentId))
    )

    Leave a comment:


  • MyloStark
    replied
    In reality they would prefer to change a single appointment so, in theory, it would be 1:1 but for customers it doesn't matter, that's why I was saying that the relationship could also be changed, the important thing is that the automatic association works.
    Appointments and Contracts are Custom entities​.

    Leave a comment:


  • rabii
    replied
    only thing you should noticed is that the lead -> has Many appointments, which means you will have to select only one of the appointments. question Appointment is this a custom entity or is it (Meeting) ?

    Leave a comment:


  • MyloStark
    replied
    Exact. When I create a new Contract I would like to insert only the Lead and then automatically correlate the Appointment, perhaps with a formula, but that would be fine also a different relationship that shows the correlated Appointment in the lower panels as happens in Lead>Appointments/Contracts

    Leave a comment:

Working...