I am trying to create a Text Message activity record via JS that is called when an HTML button is clicked. I've gotten most of the kinks worked out but now when I click the button I get the following error:
"Index (zero based) must be greater than or equal to zero and less than the size of the argument list."
I assume it has something to do with the object "data" that lists the values needed to create the record but there's not indexing on anything. Maybe it has to do with the object property "cdi_txtmessage_activity_parties", which is an array, but maybe I'm too novice to understand what the issue is.
window.parentExecutionContext = null; window.parentFormContext = null; function InitializeButton(executionContext) { // Assign executionContext and formContext to global variables within the web resource window.parentExecutionContext = executionContext; window.parentFormContext = executionContext.getFormContext(); } function smsResponse() { window.parentFormContext.data.entity.save; var userID = Xrm.Utility.getGlobalContext().userSettings.userId; console.log(userID); var contactID = window.parentFormContext.data.entity.getId(); console.log(contactID); contactID = contactID.substring(1,contactID.length-1); console.log(contactID) var smsResponse = window.parentFormContext.getAttribute("new_smsresponse").getValue(); console.log(smsResponse); var parties = []; var recipient = {}; recipient["partyid_contact@odata.bind"] = "/contacts(" contactID ")"; recipient["participationtypemask"] = 2; parties.push(recipient); var data = { "subject": "SMS Reply", "cdi_txtmessage_activity_parties": parties, "ownerid@odata.bind": userID, "cdi_message": smsResponse, "regardingobjectid_contact@odata.bind": "/contacts(" contactID ")" } console.log(data); // create account record Xrm.WebApi.createRecord("cdi_txtmessage", data).then( .....more code