Needed to add a field to a published layer and calculate values based on existing field. Tried using "When" function but the expression has remained in "Calculating" mode for over 30 minutes (only 174 records). Can someone tell me if my syntax is off?
var target = $feature["dept_name"]
var source = $feature["user_business_unit"]
target = When(
source == 'ACOFD',
'Fire',
source == 'ALCSO',
'Sheriff',
source == 'ASESR',
'Assessor',
source == 'AUDTR',
'Auditor',
source == 'BOARD',
'BOS',
source == 'CAOFF',
'CAO',
source == 'CMDEV',
'CDA',
source == 'COLIB',
'Library',
source == 'CONSL',
'Counsel',
source == 'DAOFF',
'DA',
source == 'GENSA',
'GSA',
source == 'HDSVS',
'Health Department',
source == 'HRSVC',
'Human Resources',
source == 'ITDPT',
'ITD',
source == 'OFFCS',
'Child Services',
source == 'PBWKS',
'PWA',
source == 'PDOFF',
'Public Defender',
source == 'PROBT',
'Probation',
source == 'ROVTR',
'ROV',
source == 'SOCSA',
'Social Services',
source == 'TRETC',
'Tax Collector',
source == 'ZONE7',
'Zone 7', source)
Your code should look like this, removing the target variable:
var source = $feature["user_business_unit"]
When(
source == 'ACOFD', 'Fire',
source == 'ALCSO', 'Sheriff',
...
source == 'ZONE7', 'Zone 7',
source)
Ah, I see. I don't need to declare target field because I am already selecting it via "calculate" when clicking the header. Thanks!
I spoke to soon. Changed it to this and getting same behavior:
var source = $feature["user_business_unit"]
When(
source == 'ACOFD',
'Fire',
source == 'ALCSO',
'Sheriff',
source == 'ASESR',
'Assessor',
source == 'AUDTR',
'Auditor',
source == 'BOARD',
'BOS',
source == 'CAOFF',
'CAO',
source == 'CMDEV',
'CDA',
source == 'COLIB',
'Library',
source == 'CONSL',
'Counsel',
source == 'DAOFF',
'DA',
source == 'GENSA',
'GSA',
source == 'HDSVS',
'Health Department',
source == 'HRSVC',
'Human Resources',
source == 'ITDPT',
'ITD',
source == 'OFFCS',
'Child Services',
source == 'PBWKS',
'PWA',
source == 'PDOFF',
'Public Defender',
source == 'PROBT',
'Probation',
source == 'ROVTR',
'ROV',
source == 'SOCSA',
'Social Services',
source == 'TRETC',
'Tax Collector',
source == 'ZONE7',
'Zone 7', source)
I used the same syntax to test on a sample dataset and it worked as expected. Can you edit individual records?