Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Set Field script step not doing what is expected

Featured Replies

  • Newbies

I have a script shown below, that works fine until it gets to the set field steps that increment a counter and a question id. The steps simply put a 1 into each new record instead of adding 1 to each previous value. Anyone know how to fix this so it does increment the fields? I'm stuck until this is working. All help appreciated.

New Record/Request

Set Field [survey Answers::gLoopCounter;0]

Set Field [survey Answers::n_question_id;0]

Loop

Set Field [survey Answers::n_survey_id ;Survey Answers::n_survey_id = Survey Respondents::n_survey_id]

Set Field [survey Answers::n_respondent_id;Survey Answers::n_repondent_id = Survey Respondents::n_dem_respondent_id]

Set Field [survey Answers::gLoopCounter;Survey Answers::gLoopCounter = Survey Answers::gLoopCounter + 1]

Set Field [survey Answers::n_question_id;Survey Answers::n_question_id = Survey Answers::n_question_id + 1]

Exit Loop If [survey Answers::gLoopCounter=40]

New Record/Request

End Loop

Go to Layout [original layout]

Is N_Question a Global field - if not, the value won't be there to increment.

  • Author
  • Newbies

n_question_id is a number field. It first gets set to 0 and then in the loop it gets set to 1. This works fine. It's the next time through the loop that it set's the n_question_id to 1 again not 2.

If I had a global field then I wouldn't end up with question id's from 1 to 40.

Am I making sense?

Whats happening here is that there is no value in N_Question the second time through because its not a global. Why not just set N_Question_ID to the gLoopCounter. This will set the Numeric value to your Global value (thus incrementing the question).

(Or set it to "Ngloopcounter+x" where x is the value you want to offset the number by.

Essentially, in your script, N_Question_Id knows nothing about the previous records N_question value.

  • Author
  • Newbies

Thanks so much for the assistance. Yep you were right, globals were the key and it solved the problem. I ended up doing the following:

#New respondent answer setup

New Record/Request

Set Field[survey Answers::gLoopCounter2; 0]

Set Field[survey Answers::g_question_id2; 0]

Loop

Set Field[survey Answers::n_survey_id; Survey Answers::n_survey_id = Survey Respondents::n_survey_id]

Set Field[survey Answers::n_repondent_id; Survey Answers::n_repondent_id = Survey Respondents::n_dem_respondent_id]

Set Field[survey Answers::gLoopCounter2; Survey Answers::gLoopCounter2 + 1]

Set Field[survey Answers::gLoopCounter; Survey Answers::gLoopCounter2]

Set Field[survey Answers::g_question_id2; Survey Answers::g_question_id2+ 1]

Set Field[survey Answers::n_question_id; Survey Answers::g_question_id2]

Exit Loop If[survey Answers::gLoopCounter2 = 40]

New Record/Request

End Loop

Go to Layout["Respondents" (Survey Respondents)]

Cheers

Libby - very grateful

smile.gif

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.