AnsweredAssumed Answered

Record.js : Dropdown value depends on number of related records

Question asked by Gaelle Fernandez on Jun 17, 2015
Latest reply on Jun 23, 2015 by Shijin Krishna
Hello everyone !

i'm a little stuck on this :

I have a dropdown named "Status" on my Contacts module.
There are 4 choices in this dpdwn :
  • "Pending", which is the default value.
  • "Prospect", which has to appear when the contact is related to at least 1 Quote and 0 Contract
  • "Customer", which has to appear when the contact is related to at least 1 Contract
  • "Speaker", which could be chosen by the user.
So, i wanted this dropdown field to be a calculated one, but by studio nor sugar logic, dropdown are not allowed to be calculated fields. (but in my head, the sugar formula could be something like this :

equal(count($contacts_de_devis_1),0), equal(count($contacts_contracts_1),0)
greaterThan(count($contacts_de_devis_1),0), equal(count($contacts_contracts_1),0)
So, i've chosen the customisation solution :
I'll change record.js and add a function.
In this function, i would like to count the related Quotes and the related Contracts of this contact.
And then, i would like to show the right dropdown value. (and maybe disable the field when it is prospect or customer, but i'll do this later)

Do you have any idea on how i can count the number of related records of Contacts in record.js, please?

thanks a lot !