Skip to main content

Skuid page: Calendar

Use Case: Mass Create rows on newAppts model based on screen input into a protoAppts model

Deviations from the tutorial:
1. While is used instead of an Each
2. Get row by Id (proto model has more than 1 record)

Biggest problem
1. I don’t know JavaScript
2. Reference Skuid Unique Id for get row by Id
3. All created records need to have the value of the first record stored in a custom field
     - How does one save an Id for a record that doesn’t exist (whoa - that’s deep)
4. Set the Loop Var values - it gives me errors
5. JavaScript data time syntax
6. Setting value in additionalConditions


Here’s my code attempt:



<br>var params = arguments=0];var step = params.step;<br>var $ = skuid.$;<br>// REFERENCE MODELS<br>var models = skuid.model.map();<br>var protoAppt = models.Appointment;<br>var newAppts = models.newAppts;<br>// SET DEFAULT VALUES protoModel values ==&gt; conditions on newModel<br>var proto = protoAppt.getFirstRow(); &nbsp;// can we identify the row in another way? Skuid Unique IDs<br>// GET conditions<br>// &nbsp; &nbsp; &nbsp; &nbsp;based on proto<br>var caseCondition = newAppts.getConditionByName('Case');<br>var userCondition = newAppts.getConditionByName('User');<br>var recurrencetotalCondition = newAppts.getConditionByName('RecurrenceTotal');<br>var recurrencestarttimeCondition = newAppts.getConditionByName('RecurrenceStartTime');<br>var recurrenceendtimeCondition = newAppts.getConditionByName('RecurrenceEndTime');<br>var recurrenceapptidCondition = newAppts.getConditionByName('RecurrenceApptID');<br>var recurrenceisrecurrenceCondition = newAppts.getConditionByName('RecurrenceIsRecurrence');<br>var attendanceCondition = newAppts.getConditionByName('Attendance');<br>var confirmationCondition = newAppts.getConditionByName('Confirmation');<br>// SET conditions<br>newAppts.setCondition(caseCondition,protoAppt.getFieldValue(proto,'Case__c'));<br>newAppts.setCondition(userCondition,protoAppt.getFieldValue(proto,'User__c'));<br>newAppts.setCondition(recurrencetotalCondition,protoAppt.getFieldValue(proto,'RecurrenceNumberTotal__c'));<br>newAppts.setCondition(recurrencestarttimeCondition,protoAppt.getFieldValue(proto,'StartDateTime__c'));<br>newAppts.setCondition(recurrenceendtimeCondition,protoAppt.getFieldValue(proto,'EndDateTime__c'));<br>newAppts.setCondition(recurrenceisrecurrenceCondition,protoAppt.getFieldValue(proto,'RecurrenceIsRecurrence__c'));<br>newAppts.setCondition(attendanceCondition,protoAppt.getFieldValue(proto,'Attendance__c'));<br>newAppts.setCondition(confirmationCondition,protoAppt.getFieldValue(proto,'Confirmation__c'));<br>// &nbsp; &nbsp; &nbsp; &nbsp;How do I set an Id for a record that hasn't be created in SF yet?<br>newAppts.setCondition(recurrenceapptidCondition,protoAppt.getFieldValue(proto,'Id'));<br>// SET loop vars<br>var loopRecurrenceNumber = 1;<br>var loopRecurrenceNumberTotal = protoAppt.getFieldValue(proto,'RecurrenceNumberTotal__c'));<br>var loopStartDateTime = protoAppt.getFieldValue(proto,'StartDateTime__c'));<br>var loopEndDateTime = protoAppt.getFieldValue(proto,'EndDateTime__c'));<br>// ACTION CODE - loop and set non default values<br>while(loopRecurrenceNumber &lt;= loopRecurrenceNumberTotal){<br>&nbsp; &nbsp; var row = newAppt.createRow({<br>&nbsp; &nbsp; &nbsp; &nbsp; additionalConditions: o<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET StartDateTime__c = loopStartDateTime, EndDateTime__c = loopEndDateTime, RecurrenceNumber__c = loopRecurrenceNumber<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'StartDateTime__c', value: this.Id, operator: '=', nameFieldValue: this.name}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'EndDateTime__c', value: this.Id, operator: '=', nameFieldValue: this.name}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'RecurrenceNumber__c', value: this.Id, operator: '=', nameFieldValue: this.name}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]<br>&nbsp; &nbsp; });<br>&nbsp; &nbsp; // loopStartDate + 7 days, loopEndDate + 7 days, loopRecurrenceNumber + 1<br>&nbsp; &nbsp; loopStartDateTime.setDate(loopStartDateTime.getDate() + 7);<br>&nbsp; &nbsp; loopEndDateTime.setDate(loopEndDateTime.getDate() + 7);<br>&nbsp; &nbsp; loopRecurrenceNumber.setNumber(loopRecurrenceNumber.getNumber() + 1);<br>}];<br>// FINISH CODE<br>step.navigate('step2');<br><br>

OK here we go…
1) line 38 var row = newAppt.createRow() should be newAppts.createRow()
2) this.Id and this.Name are being used to populate your datetime fields which doesn’t make any sense. Firstly you don’t need the “operator” or “nameFieldValue” parts. Those are only needed for a lookup field. You want to get the values from the proto model, and assign them to your new rows.
Try this out:


var params = argumentsm0];var step = params.step;var $ = skuid.$;<br>// REFERENCE MODELS<br>var models = skuid.model.map();<br>var protoAppt = models.Appointment;<br>var newAppts = models.newAppts;<br>// SET DEFAULT VALUES protoModel values ==&gt; conditions on newModel<br>var proto = protoAppt.getFirstRow(); &nbsp;// can we identify the row in another way? Skuid Unique IDs<br>// GET conditions<br>// &nbsp; &nbsp; &nbsp; &nbsp;based on proto<br>var caseCondition = newAppts.getConditionByName('Case');<br>var userCondition = newAppts.getConditionByName('User');<br>var recurrencetotalCondition = newAppts.getConditionByName('RecurrenceTotal');<br>var recurrencestarttimeCondition = newAppts.getConditionByName('RecurrenceStartTime');<br>var recurrenceendtimeCondition = newAppts.getConditionByName('RecurrenceEndTime');<br>var recurrenceapptidCondition = newAppts.getConditionByName('RecurrenceApptID');<br>var recurrenceisrecurrenceCondition = newAppts.getConditionByName('RecurrenceIsRecurrence');<br>var attendanceCondition = newAppts.getConditionByName('Attendance');<br>var confirmationCondition = newAppts.getConditionByName('Confirmation');<br>// SET conditions<br>newAppts.setCondition(caseCondition,protoAppt.getFieldValue(proto,'Case__c'));<br>newAppts.setCondition(userCondition,protoAppt.getFieldValue(proto,'User__c'));<br>newAppts.setCondition(recurrencetotalCondition,protoAppt.getFieldValue(proto,'RecurrenceNumberTotal__c'));<br>newAppts.setCondition(recurrencestarttimeCondition,protoAppt.getFieldValue(proto,'StartDateTime__c'));<br>newAppts.setCondition(recurrenceendtimeCondition,protoAppt.getFieldValue(proto,'EndDateTime__c'));<br>newAppts.setCondition(recurrenceisrecurrenceCondition,protoAppt.getFieldValue(proto,'RecurrenceIsRecurrence__c'));<br>newAppts.setCondition(attendanceCondition,protoAppt.getFieldValue(proto,'Attendance__c'));<br>newAppts.setCondition(confirmationCondition,protoAppt.getFieldValue(proto,'Confirmation__c'));<br>// &nbsp; &nbsp; &nbsp; &nbsp;How do I set an Id for a record that hasn't be created in SF yet?<br>newAppts.setCondition(recurrenceapptidCondition,protoAppt.getFieldValue(proto,'Id'));<br>// SET loop vars<br>var loopRecurrenceNumber = 1;<br>var loopRecurrenceNumberTotal = protoAppt.getFieldValue(proto,'RecurrenceNumberTotal__c'));<br>var loopStartDateTime = protoAppt.getFieldValue(proto,'StartDateTime__c'));<br>var loopEndDateTime = protoAppt.getFieldValue(proto,'EndDateTime__c'));<br>// ACTION CODE - loop and set non default values<br>while(loopRecurrenceNumber &lt;= loopRecurrenceNumberTotal){<br>&nbsp; &nbsp; var row = newAppts.createRow({<br>&nbsp; &nbsp; &nbsp; &nbsp; additionalConditions: a<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SET StartDateTime__c = loopStartDateTime, EndDateTime__c = loopEndDateTime, RecurrenceNumber__c = loopRecurrenceNumber<br>// You definitely do not want to use this.Id and this.Name&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'StartDateTime__c', value: loopStartDateTime}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'EndDateTime__c', value: loopEndDateTime}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'RecurrenceNumber__c', value: loopRecurrenceNumber}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]<br>&nbsp; &nbsp; });<br>&nbsp; &nbsp; // loopStartDate + 7 days, loopEndDate + 7 days, loopRecurrenceNumber + 1<br>&nbsp; &nbsp; loopStartDateTime.setDate(loopStartDateTime.getDate() + 7);<br>&nbsp; &nbsp; loopEndDateTime.setDate(loopEndDateTime.getDate() + 7);<br>&nbsp; &nbsp; loopRecurrenceNumber.setNumber(loopRecurrenceNumber.getNumber() + 1);<br>};<br>// FINISH CODE<br>step.navigate('step2');

I also see that you have a whole bunch of conditions. Are you sure that you really need that many? Can you explain why you need the Id that doesn’t exist yet? I think we can get through this one step at a time. Response to your problems listed above:

1. Not a big deal (a lot of us don’t we just look like we do :))
2. I don’t get this one
3. Not a big deal we can assign that to a variable during the save and update the rows
4. Post the errors that your getting
5. Check out the skuid tutorial on the skuid.time class here: http://help.skuidify.com/m/11720/l/129505-skuid-time
6. That’s easy 

See no big deal!


I probably don’t need that many conditions, but I’m just following a recipe for now since I don’t understand the ingredients I’m working with. 🙂

2.  (see below)
3. This solves my need for an ID that hasn’t be created - though I’m not sure how to execute this
4. Resolved
5. Of course - you even told me about this a couple days ago
6. Resolved


I probably don’t understand how this works, but my proto model has more than 1 record (potentially hundreds). How can I ensure that the data is getting pulled from the correct row?


OK you have to go to the advanced tab on the proto model and uncheck “load model data on page load” and check “create a row in model if there is none” this will give you a data entry model with one row. You really don’t want a million conditions just a data entry model which hands off the variable (start and end) to the JS snippet which creates a whole bunch of rows.


Reply