Webapp Builder is overwriting a field that is populated by a database trigger, is there a way to only have WAB send fields that are being updated?

779
1
01-23-2017 11:54 AM
ThomasFurcron
Occasional Contributor

In WAB edit widget when you create a feature it sends a request to the rest end point under the applyEdits and uses the adds function something like this.  

adds:
[{"geometry":{"x":-8925980.533247307,"y":4496880.268044835,"spatialReference":{"wkid":102100}},"attributes":{"FacilityID":null,"LeakNumber":null,"DATRPT":null,"INTGRD":null,"CURGRD":null,"INTPCT":null,"CURPCT":null,"SVY":null,"DSC":null,"FACTP":null,"PSZ":null,"PMTL":null,"PRSR":null,"JNTTP":null,"FITTP":null,"LOC":null,"LOCON":null,"LOCAT":null,"CS":null,"SUBCS":null,"PREM":null,"DIR":null,"SFX":null,"House":null,"STR":null,"ARA":null,"CITY":null,"ZIP":null,"SVCADR":null,"DATRCK":null,"RCKBY":null,"DATRGR":null,"RGRBY":null,"DATRPR":null,"RPRBY":null,"RPRMTH":null,"RPRMTHOTH":null,"WorkOrder":null,"TBREN":null,"PAGE":null,"INITServiceOrder":null,"PROJID":null,"LELPCT":null,"InstallDate":null}}]

Now all it is doing a storing the geometry and creating the objectID in the database, but it is sending all the other fields as null.  On the database end I am using SQL 2008 R2 server and have set up a trigger to autopopulate the LeakNumber and FacilityID on insert of a new row and I have checked directly after the operation and it does autopopulate those two fields.  But as soon as I update another field in the WAB editor widget the next command WAB sends is again under the applyEdits rest end point but this time using the update function, something like this: 

updates:
[{"attributes":{"FacilityID":null,"LeakNumber":null,"DATRPT":1485147600000,"INTGRD":null,"CURGRD":null,"INTPCT":null,"CURPCT":null,"SVY":null,"DSC":null,"FACTP":null,"PSZ":null,"PMTL":null,"PRSR":null,"JNTTP":null,"FITTP":null,"LOC":null,"LOCON":null,"LOCAT":null,"CS":null,"SUBCS":null,"PREM":null,"DIR":null,"SFX":null,"House":null,"STR":null,"ARA":null,"CITY":null,"ZIP":null,"SVCADR":null,"DATRCK":null,"RCKBY":null,"DATRGR":null,"RGRBY":null,"DATRPR":null,"RPRBY":null,"RPRMTH":null,"RPRMTHOTH":null,"WorkOrder":null,"TBREN":null,"PAGE":null,"INITServiceOrder":null,"PROJID":null,"LELPCT":null,"InstallDate":null,"OBJECTID":21452}}]

So the wab app builder application doesn't know that the database set the FacilityID and LeakNumber fields, so when it send the update it overwrites them back to null.  So what I have learned is each time a field is updated it sends an update for all fields.  I originally have the LeakNumber field visible and editable, then I made it not editable, then hid it completely thinking that might stop it from sending the null values, but no luck.  If I go directly to the rest endpoint and send an update that does not include anything for the LeakNumber or FacilityID fields they do not get overwritten and the update for the field still succeeds.  

Rest endpoint Update

 

I am trying to understand why this might be necessary, but can't come up with a reason.  In my mind it would make more logical sense to only send the update for the field(s) you are changing.  That said there may be a a simple explanation I don't see.  

If I could I would not use the trigger at all, but I have an existing database of leaks with unique numbers and I need to continue to populate that number without creating duplicates.  Any suggestions on how to avoid WAB overwriting those fields or suggestion on a different way to get the uniqueID into the database would be much appreciated.  

Also does anyone know if WAB developer edition allows you to determine what is sent to the rest endpoint in the editor widget?     

Tom

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Thomas,

   I have never been in your situation before, but yes you will have to use Developer edition in order to make code changes to the editor widget and try and remove those fields that are null before the FeatureLayer.applyEdits is called.