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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get max length value for text field

(0) ShareShare
ReportReport
Posted on by

Hello all,

I want to create a function to retrieve the maximum length value of fullname from Contact entities. My function looks like this: 

function getCustomerNameMaxLegth() {
var max_length;
max_length = 0;
var vres = "";
try {
var oDataURI = Xrm.Page.context.getClientUrl()
+ "/XRMServices/2011/OrganizationData.svc/ContactSet?$select=FullName";

var req = new XMLHttpRequest();
req.open("GET", oDataURI, false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.send();

if ((req.readyState == 4) && (req.status == 200)) {
var vrecord = JSON.parse(req.responseText).d;
if (vrecord.results != "") {
vres = vrecord.results[0].FullName;

if (vres.length > max_length) {
max_length = vres.length;
}
}
}
}
catch (e) {
alert("Error:" + e);
}

return max_length;
}

The problem with this function is that it looks for the maximum value only in first 50 records from contact. In my contact entity i have 3000 records and i want to get the maximum length value from entire list of records.

How can i do that?

Thanks!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Hosk Profile Picture
    on at

    I don't think OData is the right tool for this, you can page through the records but if you have 3000 it will take you too long.

    You can run fetchXml with the XRMToolkit

    www.google.de/url;rct=j&q=&esrc=s&source=web&cd=1&ved=0CCEQFjAA&url=https%3A%2F%2Fxrmservicetoolkit.codeplex.com%2F&ei=F1QdVdjYM4braOfUgJAF&usg=AFQjCNGzYsndDA0d3cQJKLRAhT38DDE8Tg&sig2=3CfLBzEquTv7rwB5wfn0Lg&bvm=bv.89744112,d.d2s&cad=rjt

    You may want to try the fetchXML tool in the XRMToolkit to see if it can get the max for a string.length

    blog.customereffective.com/.../great-fetchxml-tool-for-microsoft-dynamics-crm.html

    if you can't you can either retrieve all the records and then work out the maximum string.  This doesn't sound like the best idea because you will be getting down quite a lot of data which is only going to get bigger.

    The other choices you have is to create a new field called Fullname count and calculated this when the a contact is created.  You could either do this by Javascript or a plugin.

    You could then retireve the highest

  • Community Member Profile Picture
    on at

    Thank you for your answer, Ben. I will create a new field fullname count and calculated when the contact is created.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans