0
votes

I have a url /{database}/api/data/collections/name/{name}.

How to get all entry of view {name} with getResponseHeader("Content-Range")?

1
Do you want to get the number of all entries? Do you use LotusScript, Java or SSJS calling Domino Access Services URL?Knut Herrmann
Yes, i want get the number of all entries. I use SSJS calling Domino Access Services URLChu Thị Ngọc Lê

1 Answers

1
votes

SSJS

You can get all response header fields with HttpURLConnection's method getHeaderFields().

Pick your wanted header field with get('Content-Range').

Example:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:text escape="true" id="computedField1">
        <xp:this.value><![CDATA[#{javascript:
            var url = new java.net.URL(
                "http://yourServer/yourDatabase.nsf/api/data/collections/name/All");
            var conn:java.net.HttpURLConnection = url.openConnection();
            conn.setRequestProperty("Accept", "application/json");
            if (conn.getResponseCode() == "200") {
                try {
                    return conn.getHeaderFields().get('Content-Range');
                } catch(e) {
                    return 'Error reading header field "Content-Range"';
                }
            } else {
                return 'Error ' + conn.getResponseCode() + " " + conn.getResponseMessage();
            }
        }]]></xp:this.value>
    </xp:text>
</xp:view>

This example XPage renders as result e.g. items 0-9/35 and indicates that the response includes entries 0 through 9 of a total of 35 entries.

If you want to get the total number of entries only then change the line

                    return conn.getHeaderFields().get('Content-Range');

to

                    var range = conn.getHeaderFields().get('Content-Range').get(0);
                    var total = range.substr(range.indexOf('/') + 1);
                    return total;

This will render for the same URL 35 only.

CSJS

Use XMLHttpRequest's method getResponseHeader() on client side:

var xhr = new XMLHttpRequest(); 
xhr.open('GET', url, false); 
xhr.send(null); 
var range = xhr.getResponseHeader("Content-Range");
var total = range.substr(range.indexOf('/') + 1); 
return total