We have updated our Terms of Service, Code of Conduct, and Addendum.

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

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"

Answers

  • Jon Rust
    Jon Rust Posts: 491 mod

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

  • Jon Rust
    Jon Rust Posts: 491 mod

    you could have a series of those

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

  • Jon Rust
    Jon Rust Posts: 491 mod

    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
    Jon Rust Posts: 491 mod

    you can also use the built-in Lookup function

  • Jon Rust
    Jon Rust Posts: 491 mod

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

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

  • asc_me
    asc_me Posts: 17 mod

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