I have a When statement that works! but now I need to add an IF statement that checks another field before it applies the When statement.
I have tried several attempts but nothing is working. I am wanting to check first to see if my field PROJ_BEGIN = <null> (If null-do not add phrase) else proceed with When cause. Do I need to create an if/else statement for each variable for PROJ_BEGIN?
var status = DomainName($feature, 'CURR_PHASE')
console($feature.CURR_PHASE)
var phrase = When (status == 'Construction',"Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and is anticipated to be completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Design', "Project is anticipated to begin in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and expected to be completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Completed', "Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and was completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Closeout', "Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and was completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Study', "No projected start date at this time",
"N/A")
return phrase;
Solved! Go to Solution.
No, you shouldn't need to! You can add the if before the when statement and just enclose it all in the curly bracket:
var status = DomainName($feature, 'CURR_PHASE')
console($feature.CURR_PHASE)
var phrase
if (PROJ_BEGIN != null){
phrase = When (status == 'Construction',"Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and is anticipated to be completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Design', "Project is anticipated to begin in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and expected to be completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Completed', "Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and was completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Closeout', "Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and was completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Study', "No projected start date at this time",
"N/A")
}
else {
phrase = ''
}
return phrase;
No, you shouldn't need to! You can add the if before the when statement and just enclose it all in the curly bracket:
var status = DomainName($feature, 'CURR_PHASE')
console($feature.CURR_PHASE)
var phrase
if (PROJ_BEGIN != null){
phrase = When (status == 'Construction',"Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and is anticipated to be completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Design', "Project is anticipated to begin in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and expected to be completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Completed', "Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and was completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Closeout', "Project began in the " + ($feature.PROJ_BEGIN) + " of "+ ($feature.BEGIN_YEAR) +" and was completed in the "+ ($feature.PROJ_END) + " of " + ($feature.END_YEAR),
status == 'Study', "No projected start date at this time",
"N/A")
}
else {
phrase = ''
}
return phrase;
The other way to do that is like this, returning null if the PROG_BEGIN is null. It also uses template literals
var status = DomainName($feature, 'CURR_PHASE')
console($feature.CURR_PHASE)
if ($feature.PROJ_BEGIN == null) return;
var phrase = When (status == 'Construction', `Project began in the ${$feature.PROJ_BEGIN} of ${$feature.BEGIN_YEAR} and is anticipated to be completed in the ${$feature.PROJ_END} of ${$feature.END_YEAR}`,
status == 'Design', `Project is anticipated to begin in the ${$feature.PROJ_BEGIN} of ${$feature.BEGIN_YEAR} and expected to be completed in the ${$feature.PROJ_END} of ${$feature.END_YEAR}`,
status == 'Completed', `Project began in the ${$feature.PROJ_BEGIN} of ${$feature.BEGIN_YEAR} and was completed in the ${$feature.PROJ_END} of ${$feature.END_YEAR}`,
status == 'Closeout', `Project began in the ${$feature.PROJ_BEGIN} of ${$feature.BEGIN_YEAR} and was completed in the "${$feature.PROJ_END} of ${$feature.END_YEAR}`,
status == 'Study', "No projected start date at this time",
"N/A")
return phrase;
Thank you, worked perfectly 🙂