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 :
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

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans