IF function syntax question

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

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

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.
For more options, visit https://groups.google.com/d/optout.

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

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

--
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.
For more options, visit https://groups.google.com/d/optout.

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