Select to view content in your preferred language

How to use RangeValue domains in ArcGIS JavaScript API

1609
10
10-06-2014 05:07 PM
GeoffreyWest
Frequent Contributor

I have a combo box that I would like to use a range value instead of the coded value.  What is the proper syntax?  Now I am attempting domain.ranges to no avail.

function PopulateQuantity(serviceRequestLayerFieldsQuantity) {

    var serviceRequestFieldsQuantity

    for (var i = 0; i < serviceRequestLayerFieldsQuantity.length; i++) {

        if (serviceRequestLayerFieldsQuantity.name == serviceRequestLayerInfo.QuantityFieldName) {

            serviceRequestFieldsQuantity = serviceRequestLayerFieldsQuantity.domain.ranges;

            break;

        }

    }

    var Quantity = { identifier: "id", items: [] };

    for (var i = 0; i < serviceRequestFieldsQuantity.length; i++) {

        serviceRequestFieldsQuantity.items = { id: serviceRequestFieldsQuantity.name, name: serviceRequestFieldsQuantity.name };

    }

    var QuantityStore1 = new dojo.data.ItemFileReadStore({ data: QuantityFieldType });

    dijit.byId('cbQuantity').attr('store', QuantityStore1);

}

function PopulateQuantity(serviceRequestLayerFields) {

    var serviceRequestFields

    for (var i = 0; i < serviceRequestLayerFields.length; i++) {

        if (serviceRequestLayerFields.name == serviceRequestLayerInfo.QuantityFieldName) {

            serviceRequestFields = serviceRequestLayerFields.domain.ranges;

            break;

        }

    }

    var QuantityType = { identifier: "id", items: [] };

    for (var i = 0; i < serviceRequestFields.length; i++) {

        QuantityType.items = { id: serviceRequestFields.name, name: serviceRequestFields.name };

    }

    var QuantityStore = new dojo.data.ItemFileReadStore({ data: QuantityType });

    dijit.byId('cbQuantity').attr('store', QuantityStore);

}

Tags (1)
0 Kudos
10 Replies
RiyasDeen
Frequent Contributor

Hi Geoffrey,

Range value domain is a not an array of values like coded value domain, it is a range between minimum and maximum value.

rangedomain-amd | API Reference | ArcGIS API for JavaScript

0 Kudos
GeoffreyWest
Frequent Contributor

Hi Riyas,

Thank you for your note.  I understand that the range value is not an array like coded values, however, could you please point me to the syntax of range value?  I would like to reference a range of 1-99.

0 Kudos
RiyasDeen
Frequent Contributor

Did you try

serviceRequestLayerFields.domain.minValue;

serviceRequestLayerFields.domain.maxValue;

should work, if your field has range value domain.

0 Kudos
GeoffreyWest
Frequent Contributor

Hi Riyas,

Thank you for your note, this does not work.  I also do not receive any errors in my console either.

function PopulateQuantity(serviceRequestLayerFieldsQuantity) {

    var serviceRequestFieldsQuantity

    for (var i = 0; i < serviceRequestLayerFieldsQuantity.length; i++) {

        if (serviceRequestLayerFieldsQuantity.name == serviceRequestLayerInfo.QuantityFieldName) {

            serviceRequestFieldsQuantity = serviceRequestLayerFieldsQuantity.domain.minValue;

            break;

        }

    }

    var Quantity = { identifier: "id", items: [] };

    for (var i = 0; i < serviceRequestFieldsQuantity.length; i++) {

        serviceRequestFieldsQuantity.items = { id: serviceRequestFieldsQuantity.name, name: serviceRequestFieldsQuantity.name };

    }

    var QuantityStore1 = new dojo.data.ItemFileReadStore({ data: QuantityFieldType });

    dijit.byId('cbQuantity').attr('store', QuantityStore1);

}

function PopulateQuantity(serviceRequestLayerFields) {

    var serviceRequestFields

    for (var i = 0; i < serviceRequestLayerFields.length; i++) {

        if (serviceRequestLayerFields.name == serviceRequestLayerInfo.QuantityFieldName) {

            serviceRequestFields = serviceRequestLayerFields.domain.maxValue;

            break;

        }

    }

    var QuantityType = { identifier: "id", items: [] };

    for (var i = 0; i < serviceRequestFields.length; i++) {

        QuantityType.items = { id: serviceRequestFields.name, name: serviceRequestFields.name };

    }

    var QuantityStore = new dojo.data.ItemFileReadStore({ data: QuantityType });

    dijit.byId('cbQuantity').attr('store', QuantityStore);

}

0 Kudos
RiyasDeen
Frequent Contributor

Hi Geoffrey,

Have a look at this fiddle, Edit fiddle - JSFiddle is this what you are after?

0 Kudos
GeoffreyWest
Frequent Contributor

Hi Riyas,

This solution is not successful.  I have domains chosen as short integer from 0-99 on my database side.  See my edited code below.  

unction PopulateQuantity(serviceRequestLayerFieldsQuantity) {

    var serviceRequestFieldsQuantity

    for (var i = 0; i < serviceRequestLayerFieldsQuantity.length; i++) {

        if (serviceRequestLayerFieldsQuantity.name == serviceRequestLayerInfo.QuantityFieldName) {

            serviceRequestFieldsQuantity = serviceRequestLayerFieldsQuantity.domain.minValue + "-" +  serviceRequestFieldsQuantity.domain.maxValue;

            break;

        }

    }

    var Quantity = { identifier: "id", items: [] };

    for (var i = 0; i < serviceRequestFieldsQuantity.length; i++) {

        serviceRequestFieldsQuantity.items = { id: serviceRequestFieldsQuantity.name, name: serviceRequestFieldsQuantity.name };

    }

    var QuantityStore1 = new dojo.data.ItemFileReadStore({ data: QuantityFieldType });

    dijit.byId('cbQuantity').attr('store', QuantityStore1);

}

function PopulateQuantity(serviceRequestLayerFields) {

    var serviceRequestFields

    for (var i = 0; i < serviceRequestLayerFields.length; i++) {

        if (serviceRequestLayerFields.name == serviceRequestLayerInfo.QuantityFieldName) {

            serviceRequestFields = serviceRequestLayerFieldsQuantity.domain.minValue + "-" +  serviceRequestFieldsQuantity.domain.maxValue;

            break;

        }

    }

    var QuantityType = { identifier: "id", items: [] };

    for (var i = 0; i < serviceRequestFields.length; i++) {

        QuantityType.items = { id: serviceRequestFields.name, name: serviceRequestFields.name };

    }

    var QuantityStore = new dojo.data.ItemFileReadStore({ data: QuantityType });

    dijit.byId('cbQuantity').attr('store', QuantityStore);

}

0 Kudos
RiyasDeen
Frequent Contributor

Hi geoffery,

Can you provide bit more detail on what you use case is? I'm bit confused on what is that you are exactly after

0 Kudos
GeoffreyWest
Frequent Contributor

Hi Riyas,

Please see Public Information Center

I have an application using this template and I have added a number of other requests fields such as quantity.  See my screen shot.  I would like the quantity field to be a value domain.

Capture.PNG

0 Kudos
RiyasDeen
Frequent Contributor

Hi Geoffrey,

Have a look at this fiddle Edit fiddle - JSFiddle

You can use a function like convertRangeToCode and pass your fields with domain to this function, it'll convert the range domain into a coded value domain json object which you can use to populate your dropdown list.

If the domain in already a coded value domain, it'll be returned as is.

0 Kudos