Data Blaze - Return Value From Next Cell Down

I have a DB table with 3 columns; Month, Term Code, Start Dates. When a user selects one of these from the dbselect menu in the snippet, I need whatever is in the cell below it to also be returned as a variable. Example. A student is taking off the 2305 term of classes, and is scheduled to return in the 2306 term. User selects term 2305 from the menu. Then, the snippet needs to also display "2306" as part of a text string further down on the form. Any thoughts?

You could do something like the following:

{dbselect: SELECT Term FROM Table1 ORDER BY term ASC; space=id; name=terms; multiple=yes}

Terms: {=terms}

Select a term: {formmenu: values={=terms}; itemformatter=(item) -> item.term; name=selected} (the formatting is optional)

Selected item: {=selected}
Selected term: {=selected.term}

Next item: {=terms[location(terms, selected) + 1]}

1 Like

Thanks Scott! I got this to to work. However, I think its a bit clunky and it requires some modifying of the output so as to only show the actual Term Code instead of the whole row of Data. Maybe I am missing something? For the time being, I think I may stick with just having a 2nd dbselect menu pulling from the same table.

The itemformatter function on the formmenu in the example above is how you can format the menu entries to only show the term code.

If two dbselects are easier though, definitely go with that approach

1 Like

@scott Hey Scott. Revisiting this. How would you go about returning the next X number of terms? The X variable being whatever the user selects as a number from a dropdown menu. Example: User selects 2311 as the first term off. Then they select "4" as the number of terms the student wants off. The result would be:
"2311
2312
2401
2402"

Hey Brad! Try this out:

{dbselect: SELECT Term FROM Table1 ORDER BY term ASC; space=id; name=terms; multiple=yes}

Terms: {=terms}

Select a term: {formmenu: values={=terms}; itemformatter=(item) -> item.term; name=selected} (the formatting is optional)

Selected item: {=selected}
Selected term: {=selected.term}

How many items do you need? {formmenu: 1; 2; 3; 4; 5; 6; 7; 8; name=count_needed}
{start_position=location(terms, selected) + 1}
{next_items=slice(terms, start_position, start_position + count_needed - 1)}
Next items: {=next_items}

Once you have this next_items list, you can format it using join and map as you'd like.

Thank you @Gaurang_Tandon! Having trouble following the solution. Probably something simple I am overlooking. Love to jump on a call if we can.

Sure, feel free to DM me.