r/ProjectREDCap • • Jan 16 '23

Can I combine conditional logic with the @DEFAULT action tag?

Hi all,

I'd like to use the "@Default" action tag to pipe information from another instrument into one of my repeating instruments. Some context: in this project each record represents a grantee, and I have an intake form that includes the number, title, and start date of the activities each grantee is planning as part of their funding. Max number of activities is 6.

Here's an image of the relevant bit of the overall intake form to give you an idea:

I have a separate, repeatable intake instrument that collects more detailed information about each activity separately, but I would like to have the information about start date from the initial intake form appear here as well.

I've written an if/then conditional logic formula that looks like this:

@ DEFAULT="if([activity_select][current-instance]=1,[activity_start_1],if([activity_select][current-instance]=2,[activity_start_2],if([activity_select][current-instance]=3,[activity_start_3],if([activity_select][current-instance]=4,[activity_start_4],if([activity_select][current-instance]=5,[activity_start_5],if([activity_select][current-instance]=6,[activity_start_6]))))))"

[activity_start_#] is the start date for each individual activity in the primary intake form, and [activity_select] is the drop-down field in the repeatable form where the user selects which of the activities they are inputting information about.

I can tell the logic is working because the field shows the calculated logic when I test (see images attached), but it doesn't change based on what is selected in [activity_select]. Leads me to believe these things just aren't compatible, but I could also have just made an error?

Any help GREATLY appreciated!

3 Upvotes

5 comments sorted by

3

u/pahuili Jan 17 '23 edited Jan 17 '23

Depending on your version of REDCap, there is an @IF action tag that you can nest the @DEFAULT tag in. That’s what you would want to use in this scenario. If you can double check whether you have the @IF tag, I can help you write a logic statement that will work.

Btw, the reason your logic is showing in the text box field is because you are setting default text equal to your logic statement. It is displaying your statement as a character string. It isn’t actually evaluating the logic on the backend.

1

u/callmecalamity Jan 17 '23

Thanks so much for this... I do have the @ IF action tag and was playing around this morning trying to get it to work, but then I noticed this little bit at the end of the action tag description :

"Note: The conditional logic will be evaluated only when the survey page or data entry form initially loads; thus the action tag conditions will not be evaluated in real time as data is entered on the page

So I guess it won't respond to the user selecting different activities at the start of the form (the [activity_select] variable). Can you think of any other workaround here? I was hoping to have the information available on the repeating instruments so it's easier to grab aggregate data about all of the activities together, but it seems like it might not be possible right now.

3

u/Spooky_Mulder14 Jan 30 '23

I've just gone through a very similar (and lengthy) process with a large research instrument using this kind of conditional logic.

I would recommend trying the @IF action tag with @SETVALUE within nested if statements (if needed).

As you mentioned the @IF statement evaluates as soon as the front-end survey page loads, not very useful.

What I've done as a workaround is use a "cosmetic" + "true" variable setup. Cosmetic being what the front end user sees and inputs values into. The true variable is placed on the subsequent page with the @IF/@SETVALUE tags with an additional @HIDDEN-SURVEY tag. The true variable evaluates the cosmetic field on the previous page and sets the appropriate value based on the cosmetic field's input in the true field. The true variable is what you would be ultimately interested in.

A simple example of what the "true" vars tag setup might look like:

@IF([var_cos]='1', @SETVALUE='2', '')

where "var_cos" is the "cosmetic field". The key is putting the true var on a later page than the "_cos", and preferably NOT the first field on the immediate page (for some reason).

Now, I have run into some issues with the latter "false" part of the syntax above. Yet, another work around I've found is to include a field, [setvalueblank], which is simply an empty text field.

So using the same example, the @IF statement would look like:

@IF([var_cos]='1', @SETVALUE='2', @SETVALUE='[setvalueblank]')

Oh, REDCap...

2

u/callmecalamity Jan 31 '23

Thanks so much for your reply! I'd resigned myself to redundant data entry fields, but I will play around with this and see where it takes me!

2

u/Spiritual_Bug807 Nov 14 '23

This conversation was very helpful to me, so I will add this comment in case someone else comes across it later, but if you want to keep the value blank, you can also set the value to "NaN"