Select to view content in your preferred language

Find and Identify Alert for No Records

827
3
05-31-2012 04:53 AM
PatrickKielty
Occasional Contributor
I am trying to recreate the Show Find Task results in DataGrid

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/find_map_datag...

everything works fine, but i want to add an alert/message when no records are found. Seems like a simple task but i cannot figure it out?

Any help would be great
0 Kudos
3 Replies
SrikanthNarra
Emerging Contributor
Hi pjkielty,

               "results.length" will give you how many results are fetched from the query.So you can check this condition if the results are zero then you for your interested and sweet alert message.
0 Kudos
BenFousek
Deactivated User
var query = (qu).split(' ').join('%');
if (query == '') {
    dojo.byId('parcel_search_info').innerHTML = '<span style="color:#900;">You must enter a search value. Try again.</span>'
} else if (new String(query).length < 3) {
    dojo.byId('parcel_search_info').innerHTML = '<span style="color:#900;">Searchs must contain at least 3 characters. Try again.</span>'
} else {
    dojo.byId('parcel_search_info').innerHTML = '<img src="images/waiting.gif" /> Searching...';
    var qt = new esri.tasks.QueryTask(config.parcelQueryUrl + '?token=' + config.app.token);
    var q = new esri.tasks.Query();
    q.returnGeometry = true;
    q.outFields = config.parcelQueryOutFields;
    q.where = "UPPER(PID) like '%" + query.toUpperCase() + "%' or UPPER(ADDRESS) like '%" + query.toUpperCase() + "%' or UPPER(OWNER) like '%" + query.toUpperCase() + "%'";
    qt.execute(q, function(results) {
        if (results.features.length == 0) {
            dojo.byId('parcel_search_info').innerHTML = '<span style="color:#900;">Sorry, but your search did not return any parcels. Try again.</span>'
        } else if (results.features.length > 120) {
            dojo.byId('parcel_search_info').innerHTML = '<span style="color:#900;">Sorry, but your search returned too many parcels. Try again.</span>'
        } else {
            //build grid
        }
    })
}


[HTML]<h3>Enter Parcel ID (PID), address or owner</h3>
<form action="javascript:viewer.parcelSearch()">
    <input id="parcel_search_value" dojoType="dijit.form.TextBox" placeholder="PID, address or owner" style="width:250px; font-size:14px;" />
    <br />
    <div dojoType="dijit.form.Button" iconClass="iconSearch" type="submit" style="margin-top:8px;">SEARCH</div>
</form>
<div id="parcel_search_info" style="margin-top:4px;"></div>[/HTML]

This is a query, but the same principle. Other point of info options include a dialog, tooltip, js alert, etc. I saw a pretty cool one the other day that displayed info in the textbox itself with different colored text.
0 Kudos
PatrickKielty
Occasional Contributor
Thanks to both or you for your response.

The results.length worked great.
0 Kudos