Populate form-connected widgets with openDialog

Hello, I need a little direction.

I read in the documentation about the parameters for openDialog(dialog, data, opts) with data being an “optional record that is used to populate form-connected widgets in the dialog.” How to define that record and pass it to the widget is where I get lost.

I have a Company data model and a Notes data model. Each note is associated with a company. In my CompanyForm dialog view, I want to create a button for a new note associated with that company, so essentially I need to populate the company Select widget on the NotesForm dialog when calling openDialog() with the button.

Took a shot in the dark with the following:

var opts = {};
var data = context.getForm('CompanyForm');
var record = data.createRecord();
context.openDialog('NotesForm', record, opts);

Thanks in advance

Hi Nathan,

You can access the passed record in dialog’s viewload event

You can access using:

For passed data:
var data = context.getForm(‘CompanyForm’);
var record = {NoteName: “Caligraphic”}
context.openDialog(‘NotesForm’, record, opts);

You can access in viewload event using:
var NoteName = event.record.NoteName;

Please let me know in case you have any queries

Hi Nathan,

You’re on the right track. When you create the record from your company-form you will get a record describing a company, but what you want to pass to your dialog is a record of the Notes-model.

Now, I havent seen your app so I will make some assumptions:

  1. In your company-view you have a datagrid for listing the associated notes.
  2. You want to add notes that are connected to company contained in your company-form.

If that’s true then you can do the following:

  1. Create a button for adding a new note.
  2. In the click-event for the button, do the following:

a) Get the datagrid holding the notes: var notesGrid = context.getWidget(“DataGrid_0”); // Change the widget-id to what it is in your view
b) Create a new notes-record and pass it to the Notes-dialog:
var newNote = notesGrid.newRecord({});
context.openDialog(“NotesForm”, newNote);

The newly created Notes-record will be of the right kind and it will “connected” to the datagrid in your companyform, once the Notes-dialog is closed the (and the notes-record is being submitted/saved) it will end up in the Notes-grid on your company-form.

Let me know if this is what you are trying to do or if I can help you in any other way!

Thanks and welcome to the appivo-forum !


Should also mention - if you follow my way here you do not need to have a widget for selecting a company, that relation will be implicitly established by the fact that the Notes-record is associated with the Notes-grid (which in turn models the companys related notes).

Thanks @Johan, I’m still not able to get it to work the way I want to.

Here is my button click event code:

var opts = {};
var notesGrid = context.getWidget('TextField_0'); //get company name
var newNote = notesGrid.newRecord({});
context.openDialog('NotesForm', newNote, opts);

Here is the error it produces:

notesGrid.newRecord is not a function

Here is what I’m trying to do:

I have a data grid with a list of records from the Company data model. I double click a row to open the company record in a new dialog. I want to be able to click ‘New Note’ from the CompanyForm to open a new NoteForm dialog and have the Company Select (Select2_0) Widget auto-set to the company name from the previous dialog.

Hi Nathan,

You seem to be fetching the wrong widget - your variable notesGrid is fetching a text-field, you should be fetching the data-grid listing the notes instead. Then in the 2nd popup you wont actually need the select for company as that will be implicit.

Hope this helps !



Thanks @Johan, I see how it works now!

I see what you mean but not needing the select widget now. The reason I still wanted to use it though is so the NotesForm looks the same to the user as the add note NotesForm available from my NotesList view, which allows the user to create a new note and select the company it applies to.

Would you suggest I use separate form views for those use cases or is there an easy way to auto-populate the select widget when going from the company view?

Thanks so much!

Hello again Nathan,

Yes, if so I would recommend different views - if you enable the select in the 2nd dialog you actually seemingly allow something that will not work, when you attach the note to the originating dialog it will still be associated with that particular company anyway.



1 Like