Update Features

1311
18
05-07-2019 01:26 PM
jaykapalczynski
Frequent Contributor

I am referencing the Update feature template in AppStudio.....

I am trying to add another Combobox AND Text field that will be populated with the appropriate values once the feature is selected.  If I add the variable below "varhabitable" The popup never occurs to allow me to click into the update popup.

If I comment this line

varhabitable = selectedFeature.attributes.attributeValue("habitable");

I can run the app but the combobox is not populated with the value of that record.

How do I build the update box with multiple Fields for update including text fields?

// signal handler for selecting features
onSelectFeaturesStatusChanged: {
   if (selectFeaturesStatus === Enums.TaskStatusCompleted) {
      if (!selectFeaturesResult.iterator.hasNext)
          return;

         selectedFeature = selectFeaturesResult.iterator.next();
         vardamageType = selectedFeature.attributes.attributeValue("typdamage");
         varhabitable = selectedFeature.attributes.attributeValue("habitable");


         // show the callout
        callout.x = mousePointX;
        callout.y = mousePointY;
        callout.visible = true;

     // set the combo box's default value
       damageComboBox.currentIndex = featAttributes.indexOf(vardamageType);
       damageComboBox2.currentIndex = featAttributes.indexOf(varhabitable);

      }
  }

					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
18 Replies
ErwinSoekianto
Esri Regular Contributor

The error I am getting in the console log when running the code you provided in the Update Attribute sample is

Error: Cannot assign [undefined] to QString

And when we query on the feature layer, some of the value on the "habitable" attribute on the features are null, so that's why it is returning "undefined"

We just need to handle this undefined properly when using QML String property or use the Javascript variable instead. 

I tested by changing to use Javascript variable and it works, 

var varhabitable = selectedFeature.attributes.attributeValue("habitable");
0 Kudos
jaykapalczynski
Frequent Contributor

I got the combo box working but trying to write the "WMA" to a text box as there are not any domains with this field.+

I am trying to use the currentValue instead of the curentIndex

I see the textbox but it is not populating the value of the WMA from the attribute value.

I am looking to update more than one field....so looking to populate the textboxes with the values of the selected feature so they can be updated?

                // signal handler for selecting features
                onSelectFeaturesStatusChanged: {
                    if (selectFeaturesStatus === Enums.TaskStatusCompleted) {
                        if (!selectFeaturesResult.iterator.hasNext)
                            return;

                        selectedFeature = selectFeaturesResult.iterator.next();

                        var damageType = selectedFeature.attributes.attributeValue("TYPE");
                        var WMA = selectedFeature.attributes.attributeValue("WMA");


                        // show the callout
                        callout.x = mousePointX;
                        callout.y = mousePointY;
                        callout.visible = true;

                        // set the combo box's default value
                        damageComboBox.currentIndex = featAttributes.indexOf(damageType)
                        
                        WMATextBox.currentValue = featAttributes.valueOf(WMA);
                        
                    }
                }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

ComboBox {
     id: damageComboBox
     width: updateWindow.width - (20 * scaleFactor)
     model: featAttributes
}            


TextField {
    //id: WMATextBox
    text: WMA
    font.pixelSize: 18 * scaleFactor
    width: 280 * scaleFactor
}‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
ErwinSoekianto
Esri Regular Contributor

 

I see the textbox but it is not populating the value of the WMA from the attribute value.

 

The values on the ComboBox are coming from the model property which is "featAttributes", that is currently contains the domain value from damageType attributes

0 Kudos
jaykapalczynski
Frequent Contributor

Yea if you see my last two posts I am trying to feed the TextField with the Value of the Variable...

If I do this it works fine:  

damageTextField.text = "Test";

But i need the value from the variable .  I cant seem to get this passed to the text: on the TextField

 var varWMA     = selectedFeature.attributes.attributeValue("WMA");

I tried   NOTE:  My TextField ID changes as I have written this a few times....

damageTextField.text = varWMA;
damageTextField.text = [varWMA];
damageTextField.text = ([varWMA]);

I also tried to write it to an object and then change that value still no go...Do I need to convert or handle the "varWMA" variable differently?

0 Kudos
ErwinSoekianto
Esri Regular Contributor

I have a suspicion that the value returned from attribute "WMA" is null or undefined. 

Can you try console logging what value and what type of object varWMA is? 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof 

Also, at this point, it may be better to get help from Esri Technical Support‌, as we will be able to help you troubleshoot and reproduce the issue for you via that channel. 

0 Kudos
jaykapalczynski
Frequent Contributor

Yea I am really confused right now.....I am sure that there is a value in every "WMA" field

I changed the variable to the vardamagetype and it works....but any other attribute in the service does NOT work...

var vardamageType = selectedFeature.attributes.attributeValue("TYPE");

// var varWMA = selectedFeature.attributes.attributeValue("FG_Symbol");

damageComboBox.currentIndex = featAttributes.indexOf(vardamageType);

damageTextField.text = vardamageType ;

The above gives me the same value ...one in the combobox and the other in the TextField

0 Kudos
jaykapalczynski
Frequent Contributor

I am very new to this AppStudio...I am using the QT Creator and not sure how to return the Console Logging....

0 Kudos
ErwinSoekianto
Esri Regular Contributor

That's okay. On that section of the code, you can console log using Javascript console operation. 

var varWMA     = selectedFeature.attributes.attributeValue("WMA");
console.log(typeof varWMA);
0 Kudos
jaykapalczynski
Frequent Contributor

just not sure where the Console.log returns the value while in QT Creator....See my post below about running in QT Creator and the two errors I am getting "undefined"  But am positive there are values in those fields.

var vardamageType = selectedFeature.attributes.attributeValue("TYPE");

var varWMA = selectedFeature.attributes.attributeValue("WMA");

var varFGSymbol = selectedFeature.attributes.attributeValue("FG_Symbol");

// set the combo box's default value
damageComboBox.currentIndex = featAttributes.indexOf(vardamageType);
damageWMA.text = varWMA;
damageFGSymbol.text = varFGSymbol;

The first works the next two do not...BUT there are values in the WMA and FG_Symbol Fields.

0 Kudos