Hello! I'm Santi.
I've tried make a python code that update a field with machine's date. This results compares another fix field and offers a result in another field.
I need update a field from another one using an intermediate field. This script works in ArcMap but when I try publish as service in WebAppbuilder not works.
Code is below:
"import arcpy
import datetime
arcpy.env.workspace = r'C:\1.SANTI\TFM\20160726_Entrega_VALLADOLID\20160726_Entrega_VALLADOLID\CAPAS_ETRS_89_PARA_PROYECTO\PRUEBAS_ONLINE_2.gdb'
capa = arcpy.GetParameterAsText(0)
current_datetime = datetime.datetime.now()
arcpy.CalculateField_management(capa, "dia_actual", datetime.datetime.weekday(current_datetime))
##print(current_datetime.strftime('%A'))
campos = ['dia_actual', 'dia_libre', 'estado']
with arcpy.da.UpdateCursor (capa, campos) as cursor:
for row in cursor:
if(row [0]==row[1]):
row[2]=2
elif (row[0]<>row[1]):
row[2]=1
cursor.updateRow(row)"
Why doesn't work in WebAppbuilder? Do I need make something before publish as service?
Thank U for your help.
If somebody answer to my mail too this is: santi04082001@gmail.com
Thank U again.
Santi... could you format your code in the post please Code formatting the Basics++
And your code may work in ArcMap WebAppbuilder, but I suspect that the programming environments are not exact. Is this the... WebAppbuilder ...you are referring to?
import arcpy
import datetime
arcpy.env.workspace = r'C:\1.SANTI\TFM\20160726_Entrega_VALLADOLID\20160726_Entrega_VALLADOLID\CAPAS_ETRS_89_PARA_PROYECTO\PRUEBAS_ONLINE_2.gdb'
capa = arcpy.GetParameterAsText(0)
current_datetime = datetime.datetime.now()
arcpy.CalculateField_management(capa, "dia_actual", datetime.datetime.weekday(current_datetime))
##print(current_datetime.strftime('%A'))
campos = ['dia_actual', 'dia_libre', 'estado']
with arcpy.da.UpdateCursor (capa, campos) as cursor:
for row in cursor:
if(row [0]==row[1]):
row[2]=2
elif (row[0]<>row[1]):
row[2]=1
cursor.updateRow(row)
Hello Dan!
I´m not very expert in this "blog".. Sorry for your inconvenience.
Before this message, is the code in python format.
This code works in ArcMap but when I want export like a geoprocessing service in WebAppBuilder doesn´t work.
Any help will be welcome!!!
Thank U for all!!
Regards.
I hate dates and time...
from datetime import datetime
noww = datetime.now()
noww
datetime.datetime(2017, 3, 12, 9, 58, 27, 29985)
str(noww)
'2017-03-12 09:58:27.029985'
b = '2017-03-12 09:58:27.029985'
b == noww
False
b == str(noww)
True
so, just make sure your input date is either a datetime object in order to compare, or compare the string representations of both... Not sure that answers your question, but it is early...
You may also want to ask your question in Web AppBuilder for ArcGIS. I don't believe AppBuilder has a widget to calculate fields, although it is being suggested as an idea Calculate Field widget. You may need to use the REST API Calculate operation to accomplish this.