Using Parameters in a Simple Datalist

      <c:FormField FieldID="EXCLUSIONS" DataType="XML" Caption="Exclude constituents with the following solicit codes">

        <c:Collection>

          <c:Fields>

            <c:FormField FieldID="ID" DataType="Guid" Hidden="true" Caption="ID" />

            <c:FormField FieldID="SOLICITCODEID" DataType="Guid" Required="true" Caption="Solicit code">

              <c:SimpleDataList SimpleDataListID="8f9da293-0452-4974-8206-6f67b3e56989" >

                <c:Params>

                  <c:Param ID="INVITATIONID">

                    <c:Value>FORM!CONTEXTID</c:Value>

                  </c:Param>

                </c:Params>

              </c:SimpleDataList>

            </c:FormField>

          </c:Fields>

        </c:Collection>

      </c:FormField>


I would like to use the parameter which I have displayed in the Exclusions collection field, but this does not seem to work. I see all the solicit codes. What steps do I need to take to make sure this will function to filter the collection field correctly?


 

Comments

  • Hi Lynne!

    You will need to create a uimodel to your form, and call YOURSIMPLEDATALIST.ResetDataSource() to make the parameter take effect.

    I hope this helps

    -Joseph Styons

    https://www.styonssoftware.com
  • I have tried that already. Somehow it does not seem to work. 
  • TL;DR: put your event handler in the collection's uimodel class, not in your "main" uimodel vb file.


    OK, Lynne, I apologize - I didn't look at your example code closely enough.

    Since your SDL fields are within a collection, there is a little more work to do.


    Collection fields are little forms-within-a-form.  They have their own UIModel class, and your event needs to be on that class.

    You can find the collection's UIModel by expanding the form's UIModel.vb file.  (Make sure 'show all files' is turned on in visual studio).

    You should see:

    1) The main form vb file

    2) A collection vb file

    3) A little XML file that tells the UIModel wizard where everything is, in case you ever use 'refresh uimodel'


    #2 is interesting to us.

    If you open it, you'll see a notice that says "Changes to this file may cause incorrect behavior and will be lost if the code is regenerated".

    So we don't really want to put our changes here if we can help it.


    Luckily, the class is marked "Partial".  That means we can create a new, separate file, give it the same class name, and the compiler will treat it as part of the generated class.

    Since the file is separate, it will be protected from any future UIModel stomping.


    So, create a new Class in visual studio, and give it the same name as the partial class.

    For example, to test this out, I made a collection called "LOCATIONS", and the generated class name was [CollectionDrivenSDLAddDataFormLOCATIONSUIModel].

    So I created a new file and called it CollectionDrivenSDLAddDataFormLOCATIONSUIModel_Custom.vb, and in that file I put this code:

    Public Class CollectionDrivenSDLAddDataFormLOCATIONSUIModel
    Private Sub _countryid_ValueChanged(sender As Object, e As ValueChangedEventArgs) Handles _countryid.ValueChanged
    STATEID.ResetDataSource()
    End Sub
    End Class

    And that worked.

    I've uploaded a working example to this repository:
    https://github.com/StyonsSoftware/Training-Public


    Once you pull it down, the files you'll want to pay attention to are:

    \\Training.Catalog\\Add forms\\CollectionDrivenSDL.Add.xml
    \\Training.UIModel\\CollectionDrivenSDLAddDataForm*.vb

    I hope this helps.  For anyone who wants a walkthrough of a simpler example, I created a short training video, which you can find here.

    Joseph Styons

    https://www.styonssoftware.com

  • Dear Joseph,

    Thanks so much for that, including the excellent video. I've been creeping towards having to create a UIModel for some Global Changes I've created, and this is an excellent introduction.

    Ciao,

    David.
  • I know this is a few years old now, but thanks for asking this question! And thanks to Joseph for providing the answer. I'd been completely stumped by this as I'd wrongly assumed the logic should be handled automatically when you create the UI model.

Categories