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 ==> conditions on newModel<br>var proto = protoAppt.getFirstRow(); // can we identify the row in another way? Skuid Unique IDs<br>// GET conditions<br>// 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>// 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 <= loopRecurrenceNumberTotal){<br> var row = newAppt.createRow({<br> additionalConditions: o<br>// SET StartDateTime__c = loopStartDateTime, EndDateTime__c = loopEndDateTime, RecurrenceNumber__c = loopRecurrenceNumber<br> {field: 'StartDateTime__c', value: this.Id, operator: '=', nameFieldValue: this.name}<br> {field: 'EndDateTime__c', value: this.Id, operator: '=', nameFieldValue: this.name}<br> {field: 'RecurrenceNumber__c', value: this.Id, operator: '=', nameFieldValue: this.name}<br> ]<br> });<br> // loopStartDate + 7 days, loopEndDate + 7 days, loopRecurrenceNumber + 1<br> loopStartDateTime.setDate(loopStartDateTime.getDate() + 7);<br> loopEndDateTime.setDate(loopEndDateTime.getDate() + 7);<br> loopRecurrenceNumber.setNumber(loopRecurrenceNumber.getNumber() + 1);<br>}];<br>// FINISH CODE<br>step.navigate('step2');<br><br>