Flex Not Retrieving Subtype Domain Values

2483
0
04-22-2013 11:27 AM
ChristinaGnadinger
New Contributor II
I hope someone can help. I've been working with code handed to us by consultants and it appears that most of the language was copied and pasted from esri / user samples .. however it's not working the way it should.

This is for our Search widgets, it is retrieving the global domains but for the different subtypes it is not pulling those values. (I am a bit fuzzy on the domain details so I apologize if my terminology is not accurate)

Anyway this is where I 'think' the issue is:

private function displayFields(graphic:Graphic, fieldName:String, fieldXML:XML, field:Field):String
    
{    
    var value:String=graphic.attributes[fieldName] ? String(graphic.attributes[fieldName]) : "";
    var codedValueDomain:CodedValueDomain;    
            
    if(layerDetails && field){
        var typeID:String = layerDetails.typeIdField ? graphic.attributes[fieldName] : null;
        if (layerDetails.typeIdField && fieldName.toUpperCase() == layerDetails.typeIdField.toUpperCase())
        {
            // replace value with feature type name
            var featureType:FeatureType = getFeatureType(typeID);
            if (featureType && featureType.name)
                value = featureType.name;
        }
        else
        {
            // replace value with coded value name if one exists
            var codedValue:CodedValue = getCodedValue(fieldName, value, typeID);
            value = codedValue.name;
        }
    }

    
    if (value)
    {
        var isDateField:Boolean;
        var dateFormat:String;
        var numFormat:String;
        if (fieldXML)
        {
            numFormat = fieldXML.@numberformat[0];
            dateFormat=fieldXML.@dateformat[0];
            if (dateFormat)
            {
                isDateField=true;
            }
        }
        if (!isDateField && field)
        {
            isDateField=field.type == Field.TYPE_DATE;
        }
        if (isDateField)
        {
            var dateMS:Number=Number(value);
            if (!isNaN(dateMS))
            {
                value=msToDate(dateMS, (dateFormat)?dateFormat:'MM/DD/YYYY');
            }
        }
    }
}



.. then ...

private function getCodedValue(fieldName:String, fieldValue:String, typeID:String):CodedValue
{
    var result:CodedValue;

    var domainsCache:Object=layerDomainsCache[queryLayer];
    if (!domainsCache)
    {
        domainsCache={}; // map from (fieldName + typeID) to CodedValueDomain
        layerDomainsCache[queryLayer]=domainsCache;
    }

    var domainsKey:String=fieldName + typeID;
    var codedValueDomain:CodedValueDomain;

    if (domainsKey in domainsCache)
    {
        codedValueDomain=domainsCache[domainsKey];
    }
    else
    {        
        if (typeID){
            var featureType:FeatureType = getFeatureType(typeID);
            if (featureType)
                codedValueDomain = featureType.domains[fieldName] as CodedValueDomain;
        }else{
            var field:Field = getField(fieldName);
            if (field)
                codedValueDomain = field.domain as CodedValueDomain;
        }
        domainsCache[domainsKey] = codedValueDomain;
    }
    
    
    
    // replace the type with the Coded Domain Value
    if (codedValueDomain)
    {
        for each (var codedValue:CodedValue in codedValueDomain.codedValues)
        {
            if (fieldValue == codedValue.code)
            {
                result=codedValue;
                break;
            }
        }
    }

    return result;    
}



In my unproductive search this looks to be reused code.

As an example if valves have domains of system, gate, etc it is properly pulling those however if a gate value has a domain specific to it then it's just returning the code and not the value.

If anyone can help with this please let me know. If you want to see the full code I can post that as well. It's a bit bouncy so I was trying to save someone the searching that I have been doing.

Thanks in advance!
Christina
Tags (2)
0 Kudos
0 Replies