Load data into a choice datatype in a widget

I am attempting to update a widget so I can use data from an object rather than a text field in the widget.

The old get_settings looked like, and a text input is displayed on the widget to enter html.

	hintText: {
		main_label: "HintText",
		csid: "HintText",
		base_format: "text",	
		settings: { required: true, hint: "Use HTML tags to enhance your content" },
	},

Text input on widget:

In the new get_settings I want to to load a list of Guided Hints from an object.

	hint: {
		main_label: "Hint text",
		csid: "Hint text",
		base_format: "choice",
		choices: hint_choices, 
		settings: { required: true, hint: "Select the tip from the list" },
	},

Choice list on widget showing dummy values

The problem I’m having is when I try and load data into hint_choices in the get_settings function it loads dummy data with negative ID’s (I’m guessing this a scope problem…?)

This is code in get_settings to pull list of hints.

	get_settings: function () {

		// *** DEV CODE (start) ***
		// 1. Lookup all "Guided Hints" for Choice list
		var hint_choices = {};
		var allHints = cs.search({
			'base_object_id':'object_guided_hints',
			'selects':[':id', cs.ref('field_guided_hints__hint')],
			'return':'data'
		});		
		var i;
		for(i in allHints) {
			const hintid = allHints[i][':id']
			const hintText = allHints[i][cs.ref('field_guided_hints__hint')]
			hint_choices[hintid] = hintText;
		}
		// 2. Build Choices (X)
		//hint_choices = cs.build_choices('object');
		// 3. Hard Code array of choices (X)
		//hint_choices = {"1": "aaaaaaaaaa <b>Hello</b>","2": "bbbbbbb <b>Hey</b>","3": "ccccccc <b>Hi</b>"},
		// 4. O/P
		cs.log('hint_choices ---> '+JSON.stringify(hint_choices));	
		// *** DEV CODE (end) ***

I’ve tried moving the code to different parts of the widget, but cant figure out how I pass the hint_choices into the get_settings function.

So what I’m asking is how do I populate hint_choices with the actual data, not the dummy?

Thanks
JonathanFS

I don’t think this will be possible using record data.

Build Studio cannot access any “real” record data. If you try to perform a cs.search within get_settings, as you have found, you will only ever get the dummy data (which is also shown in the widgets when you are building a page for example).

That aside, the data would also be different from environment to environment, so using it as a value in a setting would then potentially break when promoting to another environment with different values.

Thanks Bob, I was hoping this wasn’t the case.

Build Studio cannot access any “real” record data.

Appreciate the knowledge as always.
Thanks
JonathanFS