2

I see that the draft record in datasource is deprecated. I read the release notes but am having trouble with one bit of code. Tried to convert this:

widget.datasource.draft.Email = (newValue) ? newValue.PrimaryEmail : null;

to this:

widget.datasource.item.Email = (newValue) ? newValue.PrimaryEmail : null;

But am getting this error: Cannot set property 'Email' of null

Any suggestions on what is wrong? The widget is being passed from the onValueChange action.

Thanks

Scott
  • 477
  • 4
  • 20

2 Answers2

3

You can change the widget's datasource to the create datasource in the Property Editor on the right side. Click the datasource binding and select "[Datasource Name] (create)". (screenshot)

An alternative option if you want to keep your widget bound to the normal datasource would be to set it programmatically:

widget.datasource.modes.create.item.Email = (newValue) ? newValue.PrimaryEmail : null;

Here is further documentation for accessing the create datasource through scripting.

Erica
  • 46
  • 1
2

I believe you need to set your widget's data source to a "Create" data source, before converting to "item".

Devin Taylor
  • 825
  • 5
  • 11
  • Hmm, not sure how to do that as widget.datasource.Create() does not work. – Scott Jan 25 '17 at 23:40
  • Right now your widget should have a data source property of something like "Inherited: YourDataSource". Find the container widget it's inheriting from, it should have the data source "YourDataSource". Click on that, and you should see, among a bunch of other options, "YourDataSource (Create)". That's the data source you need to choose. – Devin Taylor Jan 26 '17 at 16:54
  • It occurs to me that your intent may not to make the widget be bound to the draft data source. In almost all cases that is what you'd want, but if this is *purely* in scripting, then the approach would be: var datasource = widget.datasource.modes.create; datasource.item.Email = (newValue) ? newValue.PrimaryEmail : null; extra variable obviously not necessary, just added for clarity. I'd caution against this approach, however, I'd recommend using app.datasources.DataSourceName.modes.create explicitly, unless it's important that it's tied to the widget's data source. – Devin Taylor Jan 26 '17 at 16:55