Page 1 of 1

Roster Auto fill from previous row

Posted: August 24th, 2025, 9:21 am
by BK Singh
Dear CSPro Team,

I am currently working on a roster where values from earlier rows (e.g., Q201 and Q202A) need to be copied into later rows automatically when certain conditions are met (based on the number entered in Q202A).
In my logic, I used the skip to statement to move directly to the next question after copying values. However, I have observed that using skip causes the copied data to be lost due to how skip logic works.

Here is the relevant part of my code:
if not special(Q201_help(m)) then
Q201_help = Q201_help(m);
Q201 = Q201_help(m);
Q202A = Q202A(m);
skip to Q201A;
exit;
endif;

My Questions

Is there a safe alternative to skip that allows auto-filling values without losing copied data?
Is there a recommended approach for preloading values from earlier rows while still keeping the questionnaire flow intact?

Context
Q201_help is numeric and uses a dynamic value set from the household roster (HHROSTER).
If the enumerator selects option 1 in Q201_help and enters 3 in Q202A, then the same data should be automatically copied into the next two rows.
After that, the enumerator should be able to select another option for Q201_help, and the previous selection should be automatically removed from the available value set.

The logic for building the dynamic value set and ending the roster when all members are selected is included below for reference.

Code: Select all

do m = 1 while m < curocc_var
    if Q202A(m) > 1 then
        // Limit duplication range to 3 rows max
        numeric limit;
        limit = Q202A(m);
        if limit > 3 then
            limit = 3;
        endif;

        if curocc_var <= m + limit - 1 then
            if not special(Q201_help(m)) then
                Q201_help  = Q201_help(m); 
                Q201       = Q201_help(m);   
                Q202A      = Q202A(m);  
                skip to Q201A;     // problem line: data disappears
                exit;
            endif;
        endif;
    endif;
enddo;


// Build dynamic value set
ValueSet respondent_valueset;
do i = 1 while i <= count(HHROSTER)
    if Q139(i) = 1 then  // check eligibility
        numeric already_selected;
        already_selected = 0;
        do j = 1 while j < curocc(SEC_2000) // check earlier rows
            if Q201_help(j) = LNO(i) then
                already_selected = 1;
            endif;
        enddo;
        if already_selected = 0 then
            respondent_valueset.add(Q130(i), LNO(i));
        endif;
    endif;
enddo;

respondent_valueset.add("End Roster", 99);
setvalueset(Q201, respondent_valueset);

if respondent_valueset.length() = 0 then
    endlevel;  // auto end roster when all members selected
else
    setvalueset(Q201_help, respondent_valueset);
endif;

setcapturetype(Q201_help, 1);
I would greatly appreciate your guidance on how to handle this scenario without relying on skip, so that auto-copied values are preserved and enumerators can still review or edit responses.

Best regards,
BK Singh

Re: Roster Auto fill from previous row

Posted: August 25th, 2025, 9:12 am
by savy
As you noticed, skipped fields data is removed when the case is saved. Your options are
1. Use Advance and conditionally endgroup to end the roster.
https://www.csprousers.org/help/CSPro/a ... ement.html
https://www.csprousers.org/help/CSPro/e ... ement.html
2. Use savepartial followed by stop in the postproc of the level to always save the questionnaires in partialsave mode. The skipped field data is retained when the case is saved using partialSave.
https://www.csprousers.org/help/CSPro/s ... ction.html

Re: Roster Auto fill from previous row

Posted: August 26th, 2025, 12:47 am
by BK Singh
Dear Savy,

Thank you for your reply.
Unfortunately, the suggested approaches do not fully meet the requirements. When using "Advance", it seems to override all the other conditions in the code.

Thank you for your support.

Re: Roster Auto fill from previous row

Posted: August 26th, 2025, 8:20 am
by savy
You should use InAdvance function to conditionally run your logic
https://www.csprousers.org/help/CSPro/i ... ction.html

Re: Roster Auto fill from previous row

Posted: August 27th, 2025, 1:11 am
by BK Singh
Dear Savy,

I hope this message finds you well.

Unfortunately, I was not able to implement the changes as per your suggestion. May I kindly request you to share the modified code instead? This will greatly help me.

Thank you very much for your guidance and support.

Thank you