Add days to date Formula

I have this formula which adds days from Date Field A: addDays($date_a_c,259) . It gives me a date calced off of Date A and puts it to Date Field B. I need a formula which does this, unless Date Field D has a date, in which it should calc from field D.

I cant seem to figure it out. Can I get some pointers to which formula to use there? My rough idea is something like this: addDays($date_a_c, or(addDays($date_d_c,259)) , but of course this doesnt work.

Parents
  • Hi James,

    You'll want to make use of the ifElse statement:

    ifElse(empty($date_d_c), addDays($date_a_c, 259), addDays($date_d_c, 259))
    

    I hope that helps!

    -Alan

  • This looked like it should work for me, but in my formula builder, it will not accept  "empty."
    It shows:

    Invalid Formula

    empty: No such function defined

    Do you know what else can be used?

  • My apologies! Try this formula instead:

    ifElse(equal($date_d_c, ""), addDays($date_a_c, 259), addDays($date_d_c, 259))
    

    -Alan

Reply Children
  • THAT WORKED!! Im very grateful. Thank you!

  • Hi,

    Can u please help me to built a formula in which i want to show the value of field due date on the basis of the filed category(A drop down with the value Hot,Warm,Cold)

    I want to check if the value of category = Hot, then due date(by default populate value)= today + 1 days

    if the value of category = Warm, then due date(by default populate value)= today + 3 days

    if the value of category = Cold, then due date(by default populate value) = today + 5 days

    And also user can change the due date manually.

    Please reply ASAP

  • Hi Rahul,

    The formula you'll want will look something like this:

    ifElse(equal($category, "Hot"), addDays(today(), 1), ifElse(equal($category, "Warm"), addDays(today(), 3), addDays(today(), 5)))
    

    In order to make the field editable, you need to modify the vardef so that the "enforced" value is set to false. More information on how to do this can be found here. Let me know if you have any issues or questions with this!

    -Alan

  • Thanks Alan. Its working for me

  • Hi Alan,

    Thanks for the solution you provided in your last reply.

    I have a doubt regarding the default value for a single field in custom module.

    I have created two  fields, Field 1(integer type) and Field 2(integer type). i want to make sure that if user enters no value in the Field 2 and save the form then the value of Field 2 should be saved equal to the value of Field 1 entered by the user.

    if (Field2 == 0)

    then

    Field2 =  Field1 ;

    I  want to know that how we can do it from studio.

  • Hi Alan,

    Thanks for the solution you provided in your last reply.

    I have a doubt regarding the default value for a single field in custom

    module.

    I have created two  fields, Field 1(integer type) and Field 2(integer

    type). i want to make sure that if user enters no value in the Field 2 and

    save the form then the value of Field 2 should be saved equal to the value

    of Field 1 entered by the user.

    if (Field2 == 0)

    then

    Field2 =  Field1 ;

    I  want to know that how we can do it from studio.

    On Thu, May 5, 2016 at 10:50 PM, Alan Beam <sugarcrm-public@jiveon.com>

  • Hi Rahul,

    You can either 1) use Studio to set field2 = field1 and let the user override the value, or 2) use workflows or a logic hook to have field2 be blank when the form loads, then set it = field1 if it is left blank when Save is clicked.

    In other words, Studio cannot update the value of a field after Save is clicked, but workflows and logic hooks can. I hope that helps!

    -Alan

  • Yes Alan

    You are right on this. I created the before_save logic hook for it and it worked for me.

    Great thanks for your help