Call on a random student and score their response

I’m a teacher and I want to call on different students each time. I also sometimes give quizzes by asking direct questions to keep them engaged and score the quality of their answers.

This action randomly chooses a student name from a list in Drafts, tallies the number of times they have been called on and adds to their score [2] according to your choice in a prompt. The more times someone has been called on [1] the less likely they will be called on again. The format for your draft should be:

Class Name

John Johnson, 19, 5
Fred Coleman, 5, 14
Bob Bobson, 6, 9

In this scheme:
John Johnson has been called on 19x and accumulated a total of 5 points.

You can also use iOS shortcuts to choose the correct class list (Draft) by day of the week using this Shortcut. Or you could refine it further and choose a class list by time of day:

Action Link at

As a matter of fact, I’d love some input on this. The action works flawlessly within Drafts, but when I run it from Shortcuts as a “Run Action ‘Choose a Student’ on [Draft]” it behaves randomly. I’ve had this happen before on a different action and never figured out what the problem was. It doesn’t make sense to me. Any ideas?

Can you clarify what “randomly” is in quantifiable terms? Is it returning nothing, running on the wrong Draft, not running at all, etc?

Based on that, it would likely inform as to what console logging might be beneficial to add to track down the issue.

Some initial thoughts.

  1. You use the editor content rather than the draft content so it may well be using the draft being edited rather than the draft you specify in your shortcut.
  2. Your example content includes a blank line. I may simply have overlooked it, but I don’t see anything to accommodate blank lines in your code - only splitting out the title (first line/array element).

That’s helpful. Thank you.

The log has the script completing but the numbers aren’t changing. Or sometimes they do change but only after I click away to a different draft and come back. Just very odd and erratic. This is in contrast to running it within Drafts where it works perfectly every time.

I don’t think it’s the blank line because it works flawlessly when I run the action in Drafts. I think your first idea makes sense to me, but I don’t know how to use drafts content instead of editor. How would I do that? It would just be the first and last lines of my code that are using that…

let originalText = editor.getText();
// at the end

I’ve had a closer look at the algorithm,. I think it might be implicitly excluding them in hte way the lucky student is called (the null student would have no value for the score, so would never get picked).

I did note that for one or two students the setting of luckyStudent fails, and that if you cancel instead of choosing an option, NaN is set for the final value of the record, wiping the previous value.

The draft object has a content property.

That can be used for setting and getting.

Drafts also support template tags which can be evaluated using the draft.processTemplate() function.

If you take a look at the documentation on template content tags, you should see how [[line|2..]] could be used with the above function to get what you need.

In terms of updating the draft you would want the draft.update() function.

Hope that helps.

Super helpful. Was able to resolve both issues and get a script that is working great. The erratic shortcuts behavior was as you said—because I used editor instead of draft.content.

Just as importantly, I learned some things here and grew. Thanks so much for your time!

1 Like