Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DynamicForm, update existing record or creating a new one

    I'm trying to use a DynamicForm for both adding and updating records in a SQL DataSource, but I'm having problem with telling it if shall update or save.
    If the field marked with primaryKey="true" is filled then it shall make an update and if it is empty then it shall make an add operation.

    The DataSource is defined by the XML:

    <DataSource ID="Contact" serverType="sql" tableName="contact">
    <fields>
    <field name="id" type="sequence" title="ID" hidden="false" primaryKey="true"/>
    <field name="firstName" type="String" required="false" title="First Name" escapeHTML="true"/>
    <field name="lastName" type="String" required="false" title="Last Name" escapeHTML="true"/>
    </fields>
    </DataSource>

    and the JavaScript looks like this:

    <isomorphic:loadDS ID="Contact" />
    isc.DynamicForm.create({
    ID:"ContactForm",
    autoDraw:false,
    autoFetchData:true,
    dataSource: Contact,
    wrapItemTitles:false,
    height:"auto",
    width:"auto" })

    isc.Button.create({
    ID:"ContactFormNewButton",
    title:"New",
    click:"ContactForm.editNewRecord()" })

    function saveOrUpdate() {
    if (ContactForm.getField("id").getValue()==null) {
    ContactForm.setSaveOperationType(isc.DSOperationType.ADD);
    } else {
    ContactForm.setSaveOperationType(isc.DSOperationType.UPDATE);
    }
    ContactForm.saveData();
    }

    isc.Button.create({
    ID:"ContactFormSaveButton",
    title:"Save",
    click:"saveOrUpdate()"
    })


    But when pressing the "Save" button the console says:

    Uncaught TypeError: Cannot read property 'UPDATE' of undefined
    at saveOrUpdate ((index):78)
    at _3.eval [as click] (eval at isc__makeFunction (ISC_Core.js?isc_version=v11.1p_2017-11-02.js:77), <anonymous>:3:8)
    at _3.isc_StatefulCanvas_handleActivate [as handleActivate] (ISC_Foundation.js?isc_version=v11.1p_2017-11-02.js:233)
    at _3.isc_StatefulCanvas_handleClick [as handleClick] (ISC_Foundation.js?isc_version=v11.1p_2017-11-02.js:234)
    at _3.isc_c_EventHandler_bubbleEvent [as bubbleEvent] (ISC_Core.js?isc_version=v11.1p_2017-11-02.js:2042)
    at _3.isc_c_EventHandler_handleClick [as handleClick] (ISC_Core.js?isc_version=v11.1p_2017-11-02.js:1898)
    at _3.isc_c_EventHandler__handleMouseUp [as $k5] (ISC_Core.js?isc_version=v11.1p_2017-11-02.js:1883)
    at _3.isc_c_EventHandler_handleMouseUp [as handleMouseUp] (ISC_Core.js?isc_version=v11.1p_2017-11-02.js:1874)
    at _3.isc_c_EventHandler_dispatch [as dispatch] (ISC_Core.js?isc_version=v11.1p_2017-11-02.js:2128)
    at HTMLDocument.eval (eval at isc__makeFunction (ISC_Core.js?isc_version=v11.1p_2017-11-02.js:77), <anonymous>:3:123)

    Any idea what's wrong?

    Browser = Chrome, Version 63.0.3239.132 (Officiell version) (64 bitar)
    SmartClient Version: v11.1p_2017-11-02/Pro Development Only (built 2017-11-02)
Working...
X