# IF function syntax question

**URL:** <https://forum.dimagi.com/t/if-function-syntax-question/2709>\
**Category:** Users\
**Created:** [May 1, 2016, 11:29am UTC](https://forum.dimagi.com/t/if-function-syntax-question/2709 "2016-05-01T11:29:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Berry](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/simon_berry/32/492_2.png) [@Simon\_Berry](https://forum.dimagi.com/u/Simon_Berry)\
**Post date:** [May 1, 2016, 11:29am UTC](https://forum.dimagi.com/t/if-function-syntax-question/2709/1 "2016-05-01T11:29:51Z")

</div>

Hi

I have a hidden value called last\_visit\_success which is a date. This holds  
the last date one of our retailers was visited face-to-face (interview\_type  
= on\_site). We also contact our retailers by phone in which case  
interview\_type = by\_phone.

We use the same form for both types of interview.

When the interview\_type is on\_site I want to update the value of  
last\_visit\_success to today(). If the interview\_type is by\_phone I want to  
leave the value of last\_visit\_success unchanged. What is the syntax for  
this?

Would this work?

if(/data/interview\_type=on\_site,  
format-date(today(),'%d/%m/%y),last\_visit\_success)

Note that going into the form the value of last\_visit\_success might be ''  
(ie missing).

Thanks in anticipation of your response.

Regards

Simon  
1/5/16

---

<div class="post-metadata">

**Author:** ![Simon\_Berry](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/simon_berry/32/492_2.png) [@Simon\_Berry](https://forum.dimagi.com/u/Simon_Berry)\
**Post date:** [May 1, 2016, 12:36pm UTC](https://forum.dimagi.com/t/if-function-syntax-question/2709/2 "2016-05-01T12:36:51Z")

</div>

Sorry, I should have added that this expression is destined for the  
"Calculate Condition" field for the hidden value.

Simon

> **···**
>
> On Sunday, May 1, 2016 at 1:29:51 PM UTC+2, Simon Berry wrote: \> \> Hi \> \> I have a hidden value called last\_visit\_success which is a date. This \> holds the last date one of our retailers was visited face-to-face \> (interview\_type = on\_site). We also contact our retailers by phone in which \> case interview\_type = by\_phone. \> \> We use the same form for both types of interview. \> \> When the interview\_type is on\_site I want to update the value of \> last\_visit\_success to today(). If the interview\_type is by\_phone I want to \> leave the value of last\_visit\_success unchanged. What is the syntax for \> this? \> \> Would this work? \> \> if(/data/interview\_type=on\_site, \> format-date(today(),'%d/%m/%y),last\_visit\_success) \> \> Note that going into the form the value of last\_visit\_success might be '' \> (ie missing). \> \> Thanks in anticipation of your response. \> \> Regards \> \> Simon \> 1/5/16 \> \> \> \> \>

---

<div class="post-metadata">

**Author:** ![William\_Pride](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/w/b19c9b/32.png) [@William\_Pride](https://forum.dimagi.com/u/William_Pride)\
**Post date:** [May 1, 2016, 12:52pm UTC](https://forum.dimagi.com/t/if-function-syntax-question/2709/3 "2016-05-01T12:52:03Z")

</div>

Simon,

I believe using "/data/interview\_type=on\_site" as the display condition for  
this hidden value will achieve the desired behavior. The name "display  
condition" is slightly misleading in this context since nothing is ever  
displayed for a hidden value, but when its false it'll be as if that hidden  
value simply did not exist in the form.

-Will

> **···**
>
> On Sun, May 1, 2016 at 8:36 AM, Simon Berry wrote:
> 
> > Sorry, I should have added that this expression is destined for the  
> > "Calculate Condition" field for the hidden value.
> > 
> > Simon
> > 
> > On Sunday, May 1, 2016 at 1:29:51 PM UTC+2, Simon Berry wrote:
> > 
> > > Hi
> > > 
> > > I have a hidden value called last\_visit\_success which is a date. This  
> > > holds the last date one of our retailers was visited face-to-face  
> > > (interview\_type = on\_site). We also contact our retailers by phone in which  
> > > case interview\_type = by\_phone.
> > > 
> > > We use the same form for both types of interview.
> > > 
> > > When the interview\_type is on\_site I want to update the value of  
> > > last\_visit\_success to today(). If the interview\_type is by\_phone I want to  
> > > leave the value of last\_visit\_success unchanged. What is the syntax for  
> > > this?
> > > 
> > > Would this work?
> > > 
> > > if(/data/interview\_type=on\_site,  
> > > format-date(today(),'%d/%m/%y),last\_visit\_success)
> > > 
> > > Note that going into the form the value of last\_visit\_success might be ''  
> > > (ie missing).
> > > 
> > > Thanks in anticipation of your response.
> > > 
> > > Regards
> > > 
> > > Simon  
> > > 1/5/16
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "commcare-users" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [commcare-users+unsubscribe@googlegroups.com](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Simon\_Berry](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/simon_berry/32/492_2.png) [@Simon\_Berry](https://forum.dimagi.com/u/Simon_Berry)\
**Post date:** [May 1, 2016, 1:13pm UTC](https://forum.dimagi.com/t/if-function-syntax-question/2709/4 "2016-05-01T13:13:05Z")

</div>

Thanks William - great service for a weekend. Appreciated.

BUT I'm interested in the "Calculate Condition" (ie I want to assign a  
value to the hidden value, or leave it with its current value, based on  
certain conditions).

Regards

Simon

> **···**
>
> On Sunday, May 1, 2016 at 2:52:05 PM UTC+2, William Pride wrote: \> \> Simon, \> \> I believe using "/data/interview\_type=on\_site" as the display condition \> for this hidden value will achieve the desired behavior. The name "display \> condition" is slightly misleading in this context since nothing is ever \> displayed for a hidden value, but when its false it'll be as if that hidden \> value simply did not exist in the form. \> \> -Will \> \> On Sun, May 1, 2016 at 8:36 AM, Simon Berry \<si...@colalife.org \> wrote: \> \>\> Sorry, I should have added that this expression is destined for the \>\> "Calculate Condition" field for the hidden value. \>\> \>\> Simon \>\> \>\> \>\> On Sunday, May 1, 2016 at 1:29:51 PM UTC+2, Simon Berry wrote: \>\>\> \>\>\> Hi \>\>\> \>\>\> I have a hidden value called last\_visit\_success which is a date. This \>\>\> holds the last date one of our retailers was visited face-to-face \>\>\> (interview\_type = on\_site). We also contact our retailers by phone in which \>\>\> case interview\_type = by\_phone. \>\>\> \>\>\> We use the same form for both types of interview. \>\>\> \>\>\> When the interview\_type is on\_site I want to update the value of \>\>\> last\_visit\_success to today(). If the interview\_type is by\_phone I want to \>\>\> leave the value of last\_visit\_success unchanged. What is the syntax for \>\>\> this? \>\>\> \>\>\> Would this work? \>\>\> \>\>\> if(/data/interview\_type=on\_site, \>\>\> format-date(today(),'%d/%m/%y),last\_visit\_success) \>\>\> \>\>\> Note that going into the form the value of last\_visit\_success might be \>\>\> '' (ie missing). \>\>\> \>\>\> Thanks in anticipation of your response. \>\>\> \>\>\> Regards \>\>\> \>\>\> Simon \>\>\> 1/5/16 \>\>\> \>\>\> \>\>\> \>\>\> \>\>\> -- \>\> You received this message because you are subscribed to the Google Groups \>\> "commcare-users" group. \>\> To unsubscribe from this group and stop receiving emails from it, send an \>\> email to commcare-user...@googlegroups.com . \>\> For more options, visit https://groups.google.com/d/optout. \>\> \> \>

---

<div class="post-metadata">

**Author:** ![William\_Pride](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/w/b19c9b/32.png) [@William\_Pride](https://forum.dimagi.com/u/William_Pride)\
**Post date:** [May 1, 2016, 1:36pm UTC](https://forum.dimagi.com/t/if-function-syntax-question/2709/5 "2016-05-01T13:36:33Z")

</div>

When you say "earlier value" do you mean that this was loaded as a case  
property, or that this hidden value is being set in two places? If the  
former then my previous suggestion will work, if the latter then this  
workflow generally isn't supported (to my knowledge) - hidden values can  
have only one calculation assigned to them and don't have a notion of a  
previous/later state in XForms.

Apologies if I'm not understanding something here.

-Will

> **···**
>
> On Sun, May 1, 2016 at 9:13 AM, Simon Berry wrote:
> 
> > Thanks William - great service for a weekend. Appreciated.
> > 
> > BUT I'm interested in the "Calculate Condition" (ie I want to assign a  
> > value to the hidden value, or leave it with its current value, based on  
> > certain conditions).
> > 
> > Regards
> > 
> > Simon
> > 
> > On Sunday, May 1, 2016 at 2:52:05 PM UTC+2, William Pride wrote:
> > 
> > > Simon,
> > > 
> > > I believe using "/data/interview\_type=on\_site" as the display condition  
> > > for this hidden value will achieve the desired behavior. The name "display  
> > > condition" is slightly misleading in this context since nothing is ever  
> > > displayed for a hidden value, but when its false it'll be as if that hidden  
> > > value simply did not exist in the form.
> > > 
> > > -Will
> > > 
> > > On Sun, May 1, 2016 at 8:36 AM, Simon Berry [si...@colalife.org](mailto:si...@colalife.org) wrote:
> > > 
> > > > Sorry, I should have added that this expression is destined for the  
> > > > "Calculate Condition" field for the hidden value.
> > > > 
> > > > Simon
> > > > 
> > > > On Sunday, May 1, 2016 at 1:29:51 PM UTC+2, Simon Berry wrote:
> > > > 
> > > > > Hi
> > > > > 
> > > > > I have a hidden value called last\_visit\_success which is a date. This  
> > > > > holds the last date one of our retailers was visited face-to-face  
> > > > > (interview\_type = on\_site). We also contact our retailers by phone in which  
> > > > > case interview\_type = by\_phone.
> > > > > 
> > > > > We use the same form for both types of interview.
> > > > > 
> > > > > When the interview\_type is on\_site I want to update the value of  
> > > > > last\_visit\_success to today(). If the interview\_type is by\_phone I want to  
> > > > > leave the value of last\_visit\_success unchanged. What is the syntax for  
> > > > > this?
> > > > > 
> > > > > Would this work?
> > > > > 
> > > > > if(/data/interview\_type=on\_site,  
> > > > > format-date(today(),'%d/%m/%y),last\_visit\_success)
> > > > > 
> > > > > Note that going into the form the value of last\_visit\_success might be  
> > > > > '' (ie missing).
> > > > > 
> > > > > Thanks in anticipation of your response.
> > > > > 
> > > > > Regards
> > > > > 
> > > > > Simon  
> > > > > 1/5/16
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "commcare-users" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [commcare-user...@googlegroups.com](mailto:commcare-user...@googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "commcare-users" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [commcare-users+unsubscribe@googlegroups.com](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Simon\_Berry](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/simon_berry/32/492_2.png) [@Simon\_Berry](https://forum.dimagi.com/u/Simon_Berry)\
**Post date:** [May 2, 2016, 11:34am UTC](https://forum.dimagi.com/t/if-function-syntax-question/2709/6 "2016-05-02T11:34:26Z")

</div>

That's the key Will! I need to load values using the case management tab. I forgotten about that.

Thanks for this conversation. It has helped me see the way forward.

Simon
