Skip to main content
Question

What's the best way to do an if statement for status codes?

  • March 11, 2025
  • 8 replies
  • 5 views

What's the best way to do an if statement for status codes. Like is status=400, a new field is made statusCode = "Bad Request"

8 replies

Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

If a one off, use something like this in an evalstatusCode = `status == '400' ? "Bad Request" : statusCode`


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

you could have a series of those


  • Author
  • Participating Frequently
  • March 11, 2025

I was thinking maybe a lookup too, since status codes are pretty much static


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

Better, more scalable solution IMO is to use a lookup file (under processing, knowledge)statusCode = `C.Lookup('filename.csv','code').match(status,"return_field")`


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

you can also use the built-in Lookup function


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

AND mind the type of field status is! Is it a number or a string? You'll need to match the type


  • Author
  • Participating Frequently
  • March 11, 2025

Good point, I'll be sure to check on that


  • Employee
  • March 11, 2025

lookup is far easier to maintain than the series of if/or statements.