Skip to main content

I am using this java snippet to load all contacts associated with an Account in a related object. All the contacts load great. I am able to make changes and save the records, Yah! The problem is when I refresh the page it loads all the contacts again, including the saved contacts, so you will see the same contact twice. Does anyone know what changes I need to make to the snippet to only load the contact once and still save the contact?


var params = arguments[0];var $ = skuid&#46;$;<br />&#47;&#47; Get references to our three important Models<br />var models = skuid&#46;model&#46;map();<br />var contacts = models&#46;National_Programming_Contacts;<br />var proActions = models&#46;NationalProgrammingActions;<br />var newAttendance = models&#46;National_Programming_Attendance;<br />&#47;&#47; Now, auto-generate a new Attendance record&nbsp;<br />&#47;&#47; for each Contact in this Account&#46;<br />$&#46;each(contacts&#46;data,function(){<br />&nbsp; &nbsp; var row = newAttendance&#46;createRow({<br />&nbsp; &nbsp; &nbsp; &nbsp; additionalConditions: [<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { field: 'Contact__c', value: this&#46;Id, operator: '=', nameFieldValue: this&#46;Name }<br />&nbsp; &nbsp; &nbsp; &nbsp; ]<br />&nbsp; &nbsp; });<br />});

Tami,

Are you providing a snippet of a snippet?  :)

This snippet is only creating the newAttendance rows.  Are you saving the records too e.g. newAttendance.save({…})?

Regards,
Irvin


Hi Irvin, I am using the snippet from the create multiple row tutorial and then editing it for my purposes. What I am doing is using the save button to save the record. Are you saying that I need to add the save to the snippet or add a save action? Thank you, Tami


OK, the save button is fine.  I was not clear by just looking at the snippet.  Do you have Load Model data on page load specified for the model?


Yes I do have Load Model data checked for the Attendance model.

Here are what my Actions look like on the model.

-Activate & Set value of Model Condition
-Query Model
-Run a Skuid JavaScript Snippet
-Save Model Changes


Tami,  I’d reccomemend creating a second model that only shows contacts that do not have an associated Attendance record (subquery condition).  Then use this model to drive your autocreation snippett.   This would imply that on second page load,  the original contacts would bee excluded, and only any new contacts would be added. 



Hi Rob,

I did as you suggested and it does in fact remove the records that have an Attendance record but it still keeps loading the whole group of contacts again fresh. So it will look to the contacts and it will not show records that have an Attendance box checked but it will still load all of the contacts again showing the attendance box not checked? 
I tried moving this logic out of the drawer type and to the pop up type but there was no love on that front either. I tried adding an action at the end to clear the model thinking it will start fresh when refreshed but that didn’t work either.


Did you change the model that was loaded into your “contacts” variable in your snippet? 

I don’t think the drawer versus popup will affect things.  Its in your snippet and models. 


Maybe this is where I am missing the mark. I a contacts model that is just for contacts, I have an Attendance model which has a lookup to contacts and is where I want to automatically create new rows. Then I have an Actions model which holds the event for the attendance. So I created a new model for Attendance and added the condition of Attendance = false. I can not make that same condition on a contact model because there is no attendance field. Does that make sense?


You can make a condition on contacts so that only contacts that do not have a related record in the Attendance junction object.   Look at subcondition queries. 


Rob,


Thanks for the sub-condition query suggestion. I wrote the query but it still does not only show me contacts that do not have attended checked. The only way I have been able to only see contacts not attending is to put a filter on the Attendance object. However, the list of contacts just keep loading every time the page is called. There are over 100 records at this point. I am attaching the XML below perhaps you can see where I am going wrong. Thank you!



<pre> <models>
<model id="StateProgram" limit="20" query="true" createrowifnonefound="false" sobject="Account">
<fields>
<field id="Id"/>
</fields>
<conditions/>
<actions/>
</model>
<model id="NationalProgramActions" limit="20" query="true" createrowifnonefound="false" sobject="Action__c">
<fields>
<field id="Name"/>
</fields>
<conditions>
<condition type="modelmerge" value="" field="Name" operator="=" model="StateProgram" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
</conditions>
<actions/>
</model>
<model id="NationalProgramAttendance" limit="20" query="true" createrowifnonefound="true" sobject="Attendance__c" doclone="" type="">
<fields>
<field id="Action_Name__c"/>
<field id="Action_Name__r.Name"/>
<field id="Attended__c"/>
<field id="Contact__c"/>
<field id="Contact__r.Name"/>
<field id="Contact__r.Chapter__c"/>
<field id="Contact__r.Chapter__r.Name"/>
<field id="Contact__r.RecordTypeId"/>
<field id="Contact__r.RecordType.Name"/>
</fields>
<conditions>
<condition type="param" value="Id" field="Action_Name__r.State_Program__c" operator="=" enclosevalueinquotes="true" novaluebehavior=""/>
<condition type="modelmerge" value="" field="Action_Name__c" operator="=" model="NationalProgramActions" enclosevalueinquotes="true" mergefield="Name" novaluebehavior="deactivate" state="filterableoff" inactive="true" name="Action_Name__c"/>
</conditions>
<actions>
<action>
<actions>
<action type="setCondition" model="NationalProgramAttendance" condition="Action_Name__c" value="{{Action_Name__c}}"/>
<action type="requeryModels" model="NationalProgramAttendance" behavior="standard">
<models>
<model>NationalProgramAttendance</model>
<model>Contacts</model>
</models>
</action>
<action type="custom" snippet="generatecontacts"/>
</actions>
<events>
<event>row.created</event>
</events>
</action>
</actions>
</model>
<model id="Contacts" limit="20" query="false" createrowifnonefound="false" sobject="Contact" doclone="" type="">
<fields>
<field id="Id"/>
<field id="Chapter__c"/>
<field id="Chapter__r.Name"/>
</fields>
<conditions>
<condition type="param" value="Id" field="Chapter__r.ParentId" operator="=" enclosevalueinquotes="true" novaluebehavior=""/>
<condition type="join" value="" operator="in" field="Id" logic="" mergefield="Id" novaluebehavior="deactivate" state="" inactive="false" enclosevalueinquotes="true" joinobject="Attendance__c" joinfield="Contact__c">
<conditions>
<condition type="fieldvalue" value="true" field="Attended__c" operator="!=" mergefield="Contact__c" novaluebehavior="deactivate" enclosevalueinquotes="false"/>
</conditions>
</condition>
</conditions>
<actions/>
</model>
</models>
<components>
<pagetitle model="NationalProgramAttendance">
<actions/>
<maintitle>{{Action_Name__c}}</maintitle>
</pagetitle>
<skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="NationalProgramAttendance" buttonposition="" mode="edit">
<fields>
<field id="Attended__c" type="" valuehalign=""/>
<field id="Contact__c" valuehalign="" type=""/>
<field id="Contact__r.Chapter__c"/>
<field id="Action_Name__c" valuehalign="" type=""/>
<field id="Contact__r.RecordTypeId"/>
</fields>
<rowactions>
<action type="edit"/>
<action type="delete"/>
</rowactions>
<massactions usefirstitemasdefault="true">
<action type="massupdate"/>
<action type="massdelete"/>
</massactions>
<views>
<view type="standard"/>
</views>
</skootable>
</components>
<resources>
<labels/>
<javascript>
<jsitem location="inlinesnippet" name="generatecontacts" cachelocation="false">var params = arguments[0];
var $ = skuid.$;
// Get references to our three important Models
var models = skuid.model.map();
var contacts = models.Contacts;
var proActions = models.NationalProgramActions;
var newAttendance = models.NationalProgramAttendance;
// Now, auto-generate a new Attendance record
// for each Contact in this Account.
$.each(contacts.data,function(){
var row = newAttendance.createRow({
additionalConditions: [
{ field: 'Contact__c', value: this.Id, operator: '=', nameFieldValue: this.Name }
]
});
});</jsitem>
</javascript>
<css/>
</resources>
</skuidpage>





Reply