Jump to content

Get Count of Records from DataPage


Recommended Posts

Hi,

I am not an expert in JS but one of the useful things I came across was retrieving the number of records in, for example, a Tabular Report DataPage with JS, so that a certain script or piece of code could execute depending on whether there are results returned or not. I could not find an existing post specifically for this, so here I am.

In DPs, the total number of records can be shown at the bottom with something like "Records 1-25 of 10100". This changes depending on DP and perhaps localization settings, but we can use this to get our records displayed per page, or in the total result set.

This neat trick can help with showing the number of records displayed per results Page:

However, if you need the total number of records, we may try selecting the value from the text at the bottom of the page, with a selector like 

document.querySelector("[class='cbResultSetRecordMessage']").innerText

This will grab us the whole text, but we may need to work with the total number only. For that, we can try using something like:

var recordMsg = document.querySelector("[class='cbResultSetRecordMessage']").innerText; //returns something like 'Records 1-25 of 10100'
recordMsg.split(" ")[3] //this will return the 4th set of characters after being split by the whitespace,'10100'.
//recordMsg.split(" ")[1] will return '1-25', for example.

Another option is getting the count with a Calculated Field in the DataPage, but that also involves having to hide it afterwards, and we still need to select it with JS.

If you have other methods (more efficient, or for different use cases) to get the total count of records for use in a JS script, please share. I am not a JS expert but this may help people getting started with it :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...