Action works on macOS, not iOS

I’m creating a two-step action to prompt for the name of a grocery store and insert it into a draft. The draft is then appended to a Dropbox file for use with ledger-cli.

The problem is that the result differs between macOS and iOS. Here’s the action:

Step 1:

// Prompt for name of grocery store

var store = Prompt.create();
store.title = "Groceries transaction";
store.message = "Choose a grocery store";

var options = ["Whole Foods", "Stop and Shop", "Big Y"];
var selectedOptions = ["Whole Foods"];

store.addSelect("s1", "Select one...", options, selectedOptions, false);


if ( {
	var s = "Selected: " + store.fieldValues["s1"] + "\n\n";
    draft.setTemplateTag("store_name", store.fieldValues["s1"]);

Step 2:

[[date]] [[store_name]]

On macOS (13.1), the variable ‘store_name’ is inserted correctly, for example:

2024-02-08 Whole Foods

On iOS (15.8), it’s not inserted, and I get:

2024-02-08 [[store_name]]

Thank you for any help. First time creating an action and using Javascript, so probably operator error.


Could you share the action itself? You can share it to the directory as an unlisted action and share the link here. It’s easier to troubleshoot if we have the exact action to test with.

Here’s the link. Thank you.

The problem is that the field value for a select field in a prompt is an array, not a string. You need to get the first value returned in the case of a select that only allows single selection. So, store.fieldValues["s1"] does not include "Whole Foods" as a string, but ["Whole Foods"] as a one value array.

Try this:

let s = store.fieldValues["s1"][0]
draft.setTemplateTag("store_name", s);

You fixed it. Thank you. :yum:

1 Like