Create a toolbar button to change a value in a field - true vs false

654
3
02-25-2012 05:55 AM
StevenRipple
New Contributor
I want to create a custom button on my toolbar to change a field from true to false and back again if needed.  It is for marking a linear or area feature completed (fieldwork has been done).  Then it will show up in a different color (I know how to do this).  I just need help with some example code to get me started...  I tried finding it by searching but I don't think I'm phrasing it correctly...

I'm thinking the button would be pushed and the feature would be selected, the feature would be checked for the 'completed' field's existence, and if true it would be changed from true to false (maybe a choice would come up as to which you want instead of switching - as that could accidentally happen by touchscreen phantoms).
Tags (3)
0 Kudos
3 Replies
GarethWalters
Occasional Contributor III
Hi Steve,

If all of this is going to be done without the editform, then you need to initiate the selection of the editable record to edit.

If you use the standard select tool to highlight the feature, this will provide you a Map.SelectionBookmark object

To find that feature in the editable layer you can write Map.Layers("LayerName").Records.BookMark = Map.SelectionBookmark

Then you want to check the fields. You could do this several ways but here is a start.

if Map.Layers("LayerName").Records.Fields("completed").value = true then
Map.Layers("LayerName").Records.Fields("completed").value = false
else
  Map.Layers("LayerName").Records.Fields("completed").value = true
end if
Map.Layers("LayerName").Records.Update


The custom tool then have this script attached to the OnClick event.


Let me know if you need any more help, if not please mark as answered.

Cheers,

Gareth
0 Kudos
MatthewMurray1
New Contributor III
Steve,

If you want the form to display display what the value currently is you could have the onclick event on the tool button display the form

Applet.Forms("NAMEOFFORM").show();

then the onload event on the form could use the the follwoing code to get the selection and populate the form using two radio buttons. The value which is true for the selected record could be selected.

              var objRS;

objRS = Application.Map.SelectionLayer.Records;

objRS.Bookmark = Application.Map.SelectionBookmark;


              if (Map.Layers("NAMEOFFILE").Records.Fields("NAMEOFFIELD").value == "true")
{
  Applet.Forms("NAMEOFFORM").Pages("pg1").Controls("rdotrue").value = true;
  Applet.Forms("NAMEOFFORM").Pages("pg1").Controls("rdofalse").value = false;
}
else
{
  Applet.Forms("NAMEOFFORM").Pages("pg1").Controls("rdotrue").value = false;
  Applet.Forms("NAMEOFFORM").Pages("pg1").Controls("rdofalse").value = true;

}

The user can then change the value to either true of false and the onok event on the form can update the layer.
0 Kudos
MikeRadko
New Contributor III
I would like a single button that when clicked (OnClick) it uses the standard select tool functionality to select (and highlight) a point feature, then when the OnPointerUp event is triggered when the map pointer is released, a script is called to populate several fields of the currently selected feature.

I have OnPointerUp script working correctly using the Map.SelectionBookmark object to update my feature values, however I cannot figure out how to assign the select tool (modeselect) functionality to my custom toolbar button.  I've tried attaching the script Application.ExecuteCommand("modeselect") to the OnClick event, but it pushes control over to the standard select button and away from my custom button and thus loses focus and my OnPointerUp script call returns no selected feature.
0 Kudos