Brooklyn Errors on Clone Always model save with no rows on page load

I have a page that I use to update information in a custom object. The idea is that if I have never made an entry for a contact in this object, then a new record is created upon save. When I go back to that record, I have the page clone the original entry and present it to the user. The user than can update the data and save it. This will not update the original record as I used the clone feature. It instead creates a new record. It allows me to create a change history for that object.
It worked great until I upgraded to Brooklyn. It still works great IF there is at least 1 existing row upon page load. If there are not existing rows, then the page renders correctly without errors, but when I save it, it acts like it saves the record ( I get no error messages), but it doesn’t actually save the record. I get this error in the console. Interestingly, on the save action, I have set it to show an error if the model doesn’t save, but that doesn’t even display.

In summary:
If you set a model to “Clone Always” and you set it to “Create Default Row If Model Has None” and if your model has no rows upon page load, then when you try to save it, it does not save and you get this error in the console.

skuid__SkuidJS:8 Uncaught TypeError: Cannot read property ‘row’ of undefined at Object. (skuid__SkuidJS:8) at Function.each (skuid__JQueryJS:2) at W. (skuid__SkuidJS:8) at Function.each (skuid__JQueryJS:2) at Object.K [as save] (skuid__SkuidJS:8) at save (skuid__SkuidJS:18) at Object.h.runActionNode (skuid__SkuidJS:18) at m (skuid__SkuidJS:18) at Object.h.runActionsNode (skuid__SkuidJS:18) at HTMLDivElement. (core.js:3)

Would you be able to share any screenshots to lay out the action sequence involved? I’d like to try and reproduce this. 

I do have an action sequence and can screenshot it for you, but as part of my testing set a table to show save/cancel. Clicking that save button gives you the same error that I am showing, so it isn’t really an action sequence issue. Switching the model from “Clone data returned by Model query?” from “Yes, Always” to “No” fixes the error, but then I don’t get to have a version history I want. The attached screenshots show the offending setting. The model is set to load records on page load, limited to 1 record and to create a record if no records exist on page load. It has a condition that limits records to just those of a particular contact which it gets from a different model. Thanks!

I’m wondering if there’s something specific to the object or associated fields in your scenario that’s unhappy with the clone process. Maybe a field is set so its value must be unique?

I’ve made a simple test page with what I think are settings that match your scenario. It’s not throwing an error for me. Would you be able to test the page XML below? It should just load 1 account record in, and saving it will make a clone of the record. You’d then have 2 identical records with different unique ID’s, if it works like it is in my org.

Edit: they’d be unique with regards to the 6 fields I’ve added to the model, at any rate.

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" useviewportmeta="true" showsidebar="true" showheader="true" tabtooverride="Opportunity">    <models>
        <model id="Acc" limit="1" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Account" doclone="yes">
            <fields>
                <field id="Name"/>
                <field id="Description"/>
                <field id="Owner&#46;AccountId"/>
                <field id="Owner&#46;Account&#46;Name"/>
                <field id="OwnerId"/>
                <field id="Owner&#46;Name"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
    </models>
    <components>
        <basicfieldeditor showheader="true" showsavecancel="true" showerrorsinline="true" model="Acc" buttonposition="" uniqueid="sk-3QU1oG-137" mode="read">
            <columns>
                <column width="100%">
                    <sections>
                        <section title="Section A" collapsible="no">
                            <fields>
                                <field id="Name" valuehalign="" type=""/>
                                <field id="Description" valuehalign="" type=""/>
                                <field id="OwnerId" valuehalign="" type="" optionsource="" pagesize="5">
                                    <searchfields/>
                                    <filters/>
                                    <renderconditions logictype="and" onhidedatabehavior="keep"/>
                                    <enableconditions/>
                                </field>
                            </fields>
                        </section>
                    </sections>
                </column>
            </columns>
        </basicfieldeditor>
    </components>
    <resources>
        <labels/>
        <css/>
        <javascript/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>

Do me a favor, Put a condition on your model that ensures that no rows load… something like Id= No Id. The problem only occurs when no records load on page load. It worked for months on version 8 and only broke on upgrade to version 9 so it Doesn’t seem likely that it would be a field issue. I have no unique fields in that object other than the Id field, of course. Thanks!

Setting the model to not load data on pageload does yield the error you’d shared.

But I’m not quite sure I’ve matched your scenario, because if I have the model try to load data on a condition that’s going to fail, the Field Editor doesn’t render for me. How are you bringing the record into your model after page load? I’ve got this version below set up so you can query the model after page load, and it does appear to clone and save properly.

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" useviewportmeta="true" showsidebar="true" showheader="true" tabtooverride="Opportunity">    <models>
    <model id="Acc" limit="1" query="false" createrowifnonefound="true" datasource="salesforce" type="" sobject="Account" doclone="yes">
        <fields>
            <field id="Name"></field>
            <field id="Id" overridemetadata="false" ogdisplaytype="ID" displaytype="ID" datasource="salesforce" readonly></field>
        </fields>
        <conditions></conditions>
        <actions></actions>
    </model>
</models>
<components>
    <buttonset model="Acc" uniqueid="sk-3Qf_8o-255">
        <buttons>
            <button type="multi" label="Query Data">
                <actions>
                    <action type="requeryModel" model="Acc" behavior="standard"></action>
                </actions>
            </button>
        </buttons>
    </buttonset>
    <basicfieldeditor showheader="true" showsavecancel="true" showerrorsinline="true" model="Acc" buttonposition="" uniqueid="sk-3QU1oG-137" mode="edit">
        <columns>
            <column width="100%">
                <sections>
                    <section title="Section A" collapsible="no">
                        <fields>
                            <field id="Id" valuehalign="" type="" readonly></field>
                            <field id="Name" valuehalign="" type=""></field>
                        </fields>
                    </section>
                </sections>
            </column>
        </columns>
    </basicfieldeditor>
</components>
<resources>
    <labels></labels>
    <css></css>
    <javascript></javascript>
</resources>
<styles>
    <styleitem type="background" bgtype="none"></styleitem>
</styles>

If you set the model to create a default row If there are no rows in the model, it automatically creates a new, blank row on page load which will cause the field editor to load.

I see you have “create row if none found” marked true in your model. That should cause the field editor to appear. Not sure why it’s not loading.

I’m able to reproduce the error message, but that only seems to be happening when the model can’t base its clone off of an existing record. Is that your experience? If I query the model after page load, it clones an existing record, and the save works.

Yes. That it correct. It used to work. And it would be a real bummer if it was abandoned. I can think of a a work around if necessary, but it is a great feature to have a single page that creates a version history.

Since I’m not too familiar with your use case, I’m not sure of all the nuances, but it sounds like you may just need to make sure that there’s a default row in place before the clone/save behavior comes into play, so that all of the necessary backend metadata and processes are ready to go.

I’ve got a version of my test page below that adds a button to 1) deactivate the failing model condition and 2) query the model. After doing this, saving the record succeeds. Saving before clicking this button yields the error, but saving afterwards succeeds. I’ve created quite a few copies of “Company A” at this point.

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" useviewportmeta="true" showsidebar="true" showheader="true" tabtooverride="Opportunity">    <models>
        <model id="Acc" limit="1" query="true" createrowifnonefound="true" datasource="salesforce" type="" sobject="Account" doclone="yes">
            <fields>
                <field id="Name"/>
                <field id="Id" overridemetadata="false" ogdisplaytype="ID" displaytype="ID" datasource="salesforce" readonly="false"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="Nope" enclosevalueinquotes="true" field="Name" state="filterableon" inactive="false" name="Name"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <buttonset model="Acc" uniqueid="sk-3Qf_8o-255">
            <buttons>
                <button type="multi" label="Query Data">
                    <actions>
                        <action type="deactivateCondition" model="Acc" condition="Name"/>
                        <action type="requeryModel" model="Acc" behavior="standard"/>
                    </actions>
                </button>
            </buttons>
        </buttonset>
        <basicfieldeditor showheader="true" showsavecancel="true" showerrorsinline="true" model="Acc" buttonposition="" uniqueid="sk-3QU1oG-137" mode="edit">
            <columns>
                <column width="100%">
                    <sections>
                        <section title="Section A" collapsible="no">
                            <fields>
                                <field id="Id" valuehalign="" type="" readonly="false"/>
                                <field id="Name" valuehalign="" type=""/>
                            </fields>
                        </section>
                    </sections>
                </column>
            </columns>
        </basicfieldeditor>
    </components>
    <resources>
        <labels/>
        <css/>
        <javascript/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>

Thanks, Mark There isnt always going to be a record to clone which is why I get the error. If there isn’t a record that matches the condition criteria, I need a new record to be created. The use case is a policy that has provisions that change over time. So initially, the contact won’t have one because people aren’t born with policies. We give them one when we start working with them. So the first time the page is loaded, there is no policy for the contact, so there are no rows in the model. At this time, a new policy record should be created. Now once a policy exists for that contact, then the next time the page loads, it will have a row in that model. At that point, it should clone that row and present it to the user for updating. The user can then see the existing values and update those that need updating to new values and leave those that don’t need updating the way they are. When the user saves, it doesn’t overwrite the original record, it creates a new row so both versions are preserved. Regardless, it didn’t use to throw console errors. Now it does. I can’t imagine they designed that feature hoping it would throw console errors. I’m hoping programming could take a look and say, " hey, this thing is broken… maybe we can fix it."

Hi, Mark… Is it possible to have JavaScript check the model to see if it has rows then sets doclone = yes or doclone = no based on whether there are rows or not?

This reply was created from a merged topic originally titled Models set to “Create Default Row If Model Has None” and “Clone Always” throw con…. I have been using some models that I want to create a new record if there are no records, but clone the existing record if there is one. This lets you present the current record info to the user as a clone, allow them to update it and save it, but still have the original record so  you can create a version history. Since upgrading from 8 to 9.5.5, I now get a console error if the model has no rows on page load. It used to just create a new row. It would be great to have this functionality back.
(I reported this last week, but wanted to explain the problem more concisely)

Any more thoughts on this. I tried creating a page from scratch with the clone always setting and the create a new row of model has no rows setting and it gave me the same error message. Is this a bug that will likely be fixed, or do I need to just move on with my life and figure out a work around?

Hi Raymond, I have reproduced the issue, and submitted it to our development team as a regression, since I’ve verified that the same setup works as expected in Rockaway. I don’t know what the turnaround might be for having this addressed, but we will definitely update this conversation when the issue has been resolved. 

Thanks!