web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Web API createRecord ERROR: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

(0) ShareShare
ReportReport
Posted on by 283

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

I have the same question (0)
  • Verified answer
    Charan Raju C R Profile Picture
    7 Moderator on at

    Hi Lucas,

    First you need to remove '{' and '}' from userID.

    userID= userID.substring(1,userID.length-1);

    Then correct the syntax to set owner of the record.

    "ownerid@odata.bind": "/systemusers(" + userID + ")",

  • Suggested answer
    Lucas H Profile Picture
    283 on at

    Well that fixed it! Don't know why I didn't realize I needed to do that with the userId as well as the contactId...

    Thank you so much!

  • Charan Raju C R Profile Picture
    7 Moderator on at

    Good to hear that.

    Please mark the post as suggested answer if it has helped to resolve your problem.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans