I’m getting a VF remoting exception: “list index out of bounds: 1”
It’s happening when I attempt a save on the FollowupInteractions model after running the code at the end of this post.
Here’s the json string that VF exception is returning. I’m guessing that the “1” under “changes” is the problem?
{ "operations": ;<br> {<br> "id": "FollowupInteractions",<br> "type": "Interaction__c",<br> "updates": a<br> {<br> "id": "Date__c",<br> "targetObjects": null<br> },<br> {<br> "id": "Interaction_Category__c",<br> "targetObjects": null<br> },<br> {<br> "id": "Interaction_Purpose__c",<br> "targetObjects": null<br> },<br> {<br> "id": "Interaction_Type__c",<br> "targetObjects": null<br> },<br> {<br> "id": "Status__c",<br> "targetObjects": null<br> },<br> {<br> "id": "Patient_Case__c",<br> "targetObjects": null<br> },<br> {<br> "id": "Patient_Case__r.Name",<br> "targetObjects": null<br> },<br> {<br> "id": "Follow_up_Attempts__c",<br> "targetObjects": null<br> }<br> ],<br> "changes": {<br> "1": {<br> "Patient_Case__c": "a0wo0000002ul8fAAA",<br> "Interaction_Category__c": "Follow-up",<br> "Date__c": "2015-12-17T23:30:00.000Z",<br> "Follow_up_Attempts__c": "4",<br> "Status__c": "Scheduled",<br> "Interaction_Purpose__c": "4 week follow-up",<br> "Interaction_Type__c": "Call"<br> },<br> "2": {<br> "Patient_Case__c": "a0wo0000002ul8fAAA",<br> "Interaction_Category__c": "Follow-up",<br> "Date__c": "2016-06-22",<br> "Follow_up_Attempts__c": "1",<br> "Status__c": "Scheduled",<br> "Interaction_Purpose__c": "Chart closing",<br> "Interaction_Type__c": "Other"<br> },<br> "a0ro0000000HypUAAS": {<br> "Status__c": "Cancelled"<br> },<br> "a0ro0000000HypTAAS": {<br> "Status__c": "Cancelled"<br> },<br> "a0ro0000000HypSAAS": {<br> "Status__c": "Cancelled"<br> }<br> }<br> }<br> ]<br>}
Here’s the code:
var $ = skuid.$; <br>//Get models and rows<br>var mI = skuid.$M('ThisInteraction'),<br> mC = skuid.$M('PatientCase'),<br> mF = skuid.$M('FollowupInteractions');<br>var rI = mI.getFirstRow(),<br> rC = mC.getFirstRow();<br><br>////////////////////////////////////////<br>// Helper Functions //<br>////////////////////////////////////////<br>var getClosingDate = function(){<br> var edd = rC.Estimated_Due_Date_by_U_S__c || rC.Estimated_Due_Date_LMP__c;<br> if (!edd) {<br> edd = skuid.time.parseSFDate(rC.LMP__c) || new Date();<br> edd.setDate(edd.getDate() + 40*7);<br> } else {<br> edd = skuid.time.parseSFDate(edd);<br> }<br> var closingDate = new Date();<br> closingDate.setFullYear(edd.getFullYear(), edd.getMonth(), edd.getDate() + 4*7);<br> return skuid.time.getSFDate(closingDate);<br>};<br>var makeFollowup = function(model, date, attempt, purpose, type){<br> //Create row<br> model.createRow({<br> additionalConditions:;<br> {field: 'Date__c', value: date},<br> {field: 'Follow_up_Attempts__c', value: attempt},<br> {field: 'Status__c', value: 'Scheduled'},<br> {field: 'Interaction_Category__c', value: 'Follow-up'},<br> {field: 'Interaction_Purpose__c', value: purpose},<br> {field: 'Interaction_Type__c', value: type}<br> ]<br> });<br>};<br>var cancelScheduled = function(model){ <br> //Cancel all future interactions<br> var rowsToUpdate = {},<br> now = new Date();<br> <br> //check followup interactions model for future scheduled follow-up interactions<br> $.each(model.getRows(), function(){<br> if (skuid.time.parseSFDateTime(this.Date__c) > now && this.Status__c == 'Scheduled') {<br> rowsToUpdate&this.Id] = { Status__c: 'Cancelled' };<br> }<br> });<br> model.updateRows( rowsToUpdate ); <br>};<br>////////////////////////////////////////<br>// Action //<br>////////////////////////////////////////<br>if (rI.Interaction_Purpose__c === 'After due-date follow-up') {<br> var dt = skuid.time.parseSFDateTime(rI.Date__c);<br> dt.setDate(dt.getDate() + 1);<br> var newDate = skuid.time.getSFDateTime(dt);<br> makeFollowup(mF, newDate, '1', 'Chart closing', 'Other');<br> <br>} else {<br> //check follow-up status<br> switch (rI.Status__c) {<br> case 'Unsuccessful':<br> case 'Left message': //We did not make a connection. <br> var attempt = rI.Follow_up_Attempts__c;<br> if (!attempt) {<br> attempt = 1;<br> mI.updateRow(rI, {Follow_up_Attempts__c: '1'});<br> }<br> var dt = skuid.time.parseSFDateTime(rI.Date__c);<br> dt.setDate(dt.getDate() + 1);<br> var newDate = skuid.time.getSFDateTime(dt);<br> <br> //If we haven't tried three times<br> if (attempt < 3) { //create new row for next attempt<br> <br> // Get vairables for new row<br> attempt++;<br> makeFollowup(mF, newDate, attempt.toString(), rI.Interaction_Purpose__c, rI.Interaction_Type__c);<br> <br> } else {<br> cancelScheduled(mF);<br> if (!rC.Pregnancy_Confirmed__c){<br> //Create final followup attempt with certified letter<br> makeFollowup(mF, newDate, '4', rI.Interaction_Purpose__c, 'Certified Letter');<br> }<br> //Create 'Awesome Christina' follow-up attempt 4 for patients who still intend to abort<br> if (rC.Pregnancy_Intention__c == 'Abort') {<br> mF.createRow({<br> additionalConditions:;<br> {field: 'Date__c', value: newDate},<br> {field: 'Follow_up_Attempts__c', value: '4'},<br> {field: 'Status__c', value: 'Scheduled'},<br> {field: 'Interaction_Category__c', value: 'Follow-up'},<br> {field: 'Interaction_Purpose__c', value: rI.Interaction_Purpose__c},<br> {field: 'Interaction_Type__c', value: rI.Interaction_Type__c},<br> {field: 'Primary_Staff__c', value: '005o0000002PSJR'} //Christina<br> ]<br> });<br> }<br> var closingDate = getClosingDate();<br> makeFollowup(mF, closingDate, '1', 'Chart closing', 'Other');<br> }<br> break;<br> case 'Hung-up': //If patient hung up, do not call again.<br> mC.updateRow(rC, {Patient_Requests_No_Further_Contact__c: true});<br> cancelScheduled(mF);<br> <br> var closingDate = getClosingDate();<br> makeFollowup(mF, closingDate, '1', 'Chart closing', 'Other');<br> break;<br> case 'Successful': //We made a connection<br> if (rC.Patient_Requests_No_Further_Contact__c) {<br> cancelScheduled(mF);<br> var closingDate = getClosingDate();<br> makeFollowup(mF, closingDate, '1', 'Chart closing', 'Other');<br> } else if (rC.Pregnancy_Outcome__c && rC.Pregnancy_Outcome__c !== 'Still Pregnant') { // There was a closing event<br> cancelScheduled(mF);<br> <br> var dt = new Date();<br> dt.setDate(dt.getDate() + 1);<br> var newDate = skuid.time.getSFDateTime(dt);<br> makeFollowup(mF, newDate, '1', 'Chart closing', 'Other');<br> }<br> break;<br> }<br>}<br><br>$.blockUI({<br> message: 'Processing Complete.',<br> timeout: 2000<br>});