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?

Options

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: 439 mod
    Options

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

  • Jon Rust
    Jon Rust Posts: 439 mod
    Options

    you could have a series of those

  • Logan Carter
    Options

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

  • Jon Rust
    Jon Rust Posts: 439 mod
    Options

    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: 439 mod
    Options

    you can also use the built-in Lookup function

  • Jon Rust
    Jon Rust Posts: 439 mod
    Options

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

  • Logan Carter
    Options

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

  • asc_me
    asc_me Posts: 17 mod
    Options

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