18.4.0 released Sep 25, 2023
If task

Purpose: Select a request's task to process.

 if-task <task>
     <any code>
 [
 else-task <task>
     <any code>
 ] ...
 [
 else-task other
     <any code>
 ]
 end-task

if-task will compare a value from the last executed task-parameter with the list of string expressions, and execute code associated with the match.

If the value of task-param matches the string expression <task> in if-task, then <any code> below it is executed. If it is not a match, then the value of task-param is checked against values in "else-task" clauses, one by one until a match is found and code under that clause executes. If no match is found, then code under "else-task other" clause (if specified) is executed, otherwise program control passes outside of if-task statement.

In a given if-task statement, there can be only one "else-task other" clause, and it must be the last one in if-task statement.

For instance, a request named "customer" may be used to add a customer, update it, or delete it, and which one of these tasks is performed would be based on the value of a task-parameter, as in these URLs where task "act" can have values of "add", "update" and "delete":
http://web.site/app/customer/act/add/name/joe/email/joe@joe.com
http://web.site/app/customer/act/update/id/22/address/10+Main+Street
http://web.site/app/customer/act/delete/id/22

The request handler code in file "customer.vely" would have this code:
request-handler /customer
    out-header default

    // Specify input parameter "act" to be a task selector
    task-param act

    if-task "add"
        input-param name
        input-param email
        // Add customer
        ...
    else-task "update"
        input-param id
        input-param address
        // Update customer
        ...
    else-task "delete"
        input-param id
        // Delete customer
        ...
    else-task other
        @Unknown task.
    end-task
end-request-handler

Missing task parameters
Note that if there is no task-parameter (which is "act" in the above example), or if there is but such parameter is not present in request's input, the matched value in if-task will be an empty string (i.e. "").
Nesting and subtasks
if-task can be nested in case you want to change the task selector during the execution of a request handler, i.e. if you need to have sub-tasks. Such nesting can be up to 30 levels deep. In this example, a request "customer" has a task "act" with values of "add", "update" and "delete". A subtask "upd_type" (when task "act" has value of "update") has values of "address" and "phone":

request-handler /customer // request "customer"

    out-header default

    task-param act // task selector

    if-task "add" // task to add customer
        input-param name
        input-param email
        // Add customer
        ...
    else-task "update" // task to update customer
        input-param id
        task-param upd_type // subtask selector
        if-task "address" // subtask to update address
            input-param address
            // Update address
            ...
        else-task "phone" // subtask to update phone
            input-param phone
            // Update phone
            ...
        end-task
        ...
    else-task "delete" // task to delete customer
        input-param id
        // Delete customer
        ...
    else-task other
        @Unknown task.
    end-task
end-request-handler

See also
Request information
get-req  
if-task  
input-param  
request-body  
set-input  
set-req  
task-param    
See all
documentation


You are free to copy, redistribute and adapt this web page (even commercially), as long as you give credit and provide a link back to this page (dofollow) - see full license at CC-BY-4.0. Copyright (c) 2019-2023 Dasoftver LLC. Vely and elephant logo are trademarks of Dasoftver LLC. The software and information on this web site are provided "AS IS" and without any warranties or guarantees of any kind.