Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Account button truncation String truncating on JSON.Stringify of address array map

(0) ShareShare
ReportReport
Posted on by 225

Hello,

I am trying to build a custom CRM button that will pop open a map that displays all selected Accounts.  I have the button and I have the mapping working for a certain amount of accounts.  My issue is that somewhere between the array of accounts (this includes name, address, lat, longitude, etc.) and using JSON.stringify(MYARRAY) the string gets truncated (4000 characters including the additions made by encodeURIComponent).  So if I pick 30 accounts to plot I only get 4000 characters worth of points plotted (12-15).  Below is my code, I hope someone can help me.  This is using Javascript.  This is an onclick event from the Account homepage.  I am not having trouble getting data from my records, just passing it into my HTML (not included), I have bolded the troubled portion.

   
  function run(selectedItems) { //pass user GUID
            
        var AddressAray = new Array();
        debugger;
        for (i = 0; i < selectedItems.length; i++) 
        {
        
        
        var selectedItem = selectedItems[i].Id;
                
            RetrvAddress(selectedItem, "accounts", "address1_composite,name,address1_longitude,address1_latitude,dds_finance_bucket,_primarycontactid_value", "primarycontactid($select=fullname)",
               function (result) {                
                AddressAray.push(MixedFields);
                },
                function (error) {
                    alert('GetCurrentUserTerritory: ' + error.message);
                },
                false);
                }
                 var customParameters = encodeURIComponent(JSON.stringify(AddressAray));
        Xrm.Utility.openWebResource("../WebResources/ddscrm_/webpages/CRMPRD.XRM.GoogleMaps.html",customParameters);
        }
  
  
  
  var RetrvAddress = function (id, type, select, expand, successCallback, errorCallback, async) {

        var systemQueryOptions = "";

        if (select != null || expand != null) {
            systemQueryOptions = "?";
            if (select != null) {
                var selectString = "$select=" + select;
                if (expand != null) {
                    selectString = selectString + "&$expand=" + expand;
                }
                systemQueryOptions = systemQueryOptions + selectString;
            }
            else if (expand != null && select == null) {
                systemQueryOptions = systemQueryOptions + "$expand=" + expand;
            }
        }
        MyGUID= id;
        var clientUrl = Xrm.Page.context.getClientUrl();
        var oDataPath = clientUrl + "/api/data/v8.1/";
        var req = new XMLHttpRequest();
        req.open("GET", oDataPath + type + "(" + MyGUID+ ")" + systemQueryOptions, async);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.onreadystatechange = function () {
            if (this.readyState === 4 /* complete */) {
                if (this.status === 200) {
                    successCallback(JSON.parse(this.response));
                    debugger;
                }
                else {
                    errorCallback(errorHandler(this));
                }
            }
        };
        req.send();
    };

*This post is locked for comments

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Account button truncation String truncating on JSON.Stringify of address array map

    Mike,

    Your issue can be resolved:

    1. Change Xrm.Utility.openWebResource("../WebResources/ddscrm_/webpages/CRMPRD.XRM.GoogleMaps.html",customParameters); to

    Xrm.Utility.openWebResource("ddscrm_/webpages/CRMPRD.XRM.GoogleMaps.html",customParameters);

    2. Provide code of your html webresource. I believe you miss couple of pieces inside that causes auth errors.

  • st738407 Profile Picture
    st738407 225 on at
    RE: Account button truncation String truncating on JSON.Stringify of address array map

    Thank you, I was at one point trying that route, but got caught up with an Unauthorized error (401) with my WebAPI call and I am unfamiliar with how that would work to get the authorization added in programatically.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Account button truncation String truncating on JSON.Stringify of address array map

    Hello,

    I'm afraid you can't do anything with 4000 length. My suggestion is to move your "retrieve" logic to your webresource and pass only ids of selected records.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans