Page 1 of 1

logic on multi-occuring field

Posted: June 1st, 2012, 5:48 am
by lls
I would like to code the last field of a multi-occuring field, I'm not sure how to do that.
Q145_CONTEXT is the last question of my survey and I would like the case to be automatialy saved as partial if Q11B_ETATDOS is not = 2 and saved if = 2.
Q145_CONTEXT is a 4 occ field, if I use the code below as it is, it will be triggered at every 4 fields.

How can I make the code active only for the last occurence of Q145_CONTEXT?


PROC Q145_CONTEXT

postproc

if not Q11B_ETATDOS = 2 then
errmsg ("This case has been saved as partial") and
savepartial ();
stop();
elseif
errmsg ("This case has been saved")
endif;

Re: logic on multi-occuring field

Posted: June 4th, 2012, 9:50 am
by Gregory Martin
You can use the curocc function like this:
PROC Q145_CONTEXT

postproc

    
if curocc() = 4 then

        
if not Q11B_ETATDOS = 2 then
            
errmsg ("This case has been saved as partial") and
            
savepartial ();
            
stop();
        
        
else
            
errmsg ("This case has been saved")
        
        
endif;
    
    
endif;

Re: logic on multi-occuring field

Posted: June 5th, 2012, 5:50 am
by lls
Thank you for your advice using the curocc function.

Unfortunately something is not working.
The cases are always saved regardless Q11B_ETATDOS being 2 or an other value.
After the 'stop()' function, the case will not show the icon with a little red cross indicating it had been saved partialy.

Re: logic on multi-occuring field

Posted: June 5th, 2012, 6:02 am
by lls
Not sure if that is the best solution but replacing postproc by preproc seems to work.

Re: logic on multi-occuring field

Posted: June 5th, 2012, 7:45 am
by lls
To simplify, I have added a 1-occ field at the end of the survey with the code below.

One more question, is the 'stop()' function mandatory after 'savepartial()' ?
If I remove 'stop()', the case will be saved (not partialy saved).


PROC CLOSECASE

PREPROC

if not Q11B_ETATDOS = 2 then
errmsg ("Ce dossier a été enregistré comme dossier non clos") and
savepartial ();
stop();

else

endif;

Re: logic on multi-occuring field

Posted: June 15th, 2012, 1:29 pm
by Gregory Martin
savepartial is usually used for these reasons:

1) Save the case contents when you are working on a huge entry application and are concerned that the power may cut off and you do not want to lose the data entered.

2) If using laptops/tablets for a CAPI application, you may want to semi-regularly save the case.

3) When you are stopping data entry before the end of the questionnaire has been reached. This is typically followed by a stop command.

Do you really want to partially save your case, or is it that you do not want the keyer to enter data for Q145_CONTEXT on the fourth occurrence? If that is the case, you could write:
PROC Q145_CONTEXT

preproc

    
if curocc() = 4 and Q11B_ETATDOS <> 2 then
        
endlevel;
    
endif;