CA Service Management

Expand all | Collapse all

Spel Code: Post_Validate error message depending on the category

Jump to Best Answer
  • 1.  Spel Code: Post_Validate error message depending on the category

    Posted 05-21-2019 05:48 AM

    I'm trying make 2 different field required depending on which category is used when creating/updating a ticket.

    For this I tried to make use of the Post_Validate way to prompt an error message if the field is null.

     

    chg::z_validate_category(...) {

    string zmsg;

    if((category == "SIGSCLVM" || category == "SIGSCWVM" || category == "SIGSCPM") && (is_null(project))){
    zmsg=format("Project is REQUIRED");
    set_error(1);
    set_return_data(zmsg);
    return;

    }

    else if((category != "SIGSCLVM" || category != "SIGSCWVM" || category != "SIGSCPM") && (is_null(z_ttessa_code))){
    zmsg=format("TTESSA CODE REQUIRED");
    set_error(1);
    set_return_data(zmsg);
    return;

    }
    }

     

    When I do this. The first condition prompts the correct error message.

     

    Category = "SIGSCLVM" 

    Project = <Null>

    TTESSA Code = <Null>

     

    Error: "Project is Required"

     

    But when I do fill up the Project field. I get prompted by the 2nd error message.

     

    Category = "BSGSL" 

    Project = "Test Project"

    TTESSA Code = <Null>

     

    Error: "TESSA CODE is Required"

     

    It seems like it still tries to go through the 2nd error message even if it doesn't meet the requirement

    But when I do:

     

    Category = "BSGSL" 

    Project =  <Null>

    TTESSA Code = <Null>

     

    Error: "TESSA CODE is Required"

    It prompts the correct error message so the 2nd condition is correct.

     

    As I have been going around this for a time, I did also tried to use switch but same results. It still run through the 2nd error message still.

     

    chg::z_validate_category(...) {

    string zmsg;
    int error_msg;

    if((category == "SIGSCLVM" || category == "SIGSCWVM" || category == "SIGSCPM") && (is_null(project))) error_msg = 1;
    if((category != "SIGSCLVM" || category != "SIGSCWVM" || category != "SIGSCPM") && (is_null(z_ttessa_code)))error_msg = 2;

    switch (error_msg)
    {
         case 1:
         zmsg=format("Project is REQUIRED");
         set_error(1);
         set_return_data(zmsg);
         return;
         break;
         
         case 2:
         zmsg=format("TTESSA CODE REQUIRED");
         set_error(1);
         set_return_data(zmsg);
         return;
         break;
    }
    }

     

    Im quite at lost what could be wrong with the spl code I made.



  • 2.  Re: Spel Code: Post_Validate error message depending on the category

    Posted 05-21-2019 06:06 AM

    Currently your second condition will fire for every category, because all categories match ‘not A OR not B OR not C’ - including categories A, B and C. Do you really want TTESSA CODE to be required if ‘not A AND not B AND not C’?

     

    Regards,

    James



  • 3.  Re: Spel Code: Post_Validate error message depending on the category

    Posted 05-21-2019 09:26 AM

    you mean?

    if(category == "SIGSCLVM" || category == "SIGSCWVM" || category == "SIGSCPM"){
    if(is_null(project){
    zmsg=format("Project is REQUIRED");
    set_error(1);
    set_return_data(zmsg);
    return;

    }
    }
    else if(is_null(z_ttessa_code)){
    zmsg=format("TTESSA CODE REQUIRED");
    set_error(1);
    set_return_data(zmsg);
    return;
    }



  • 4.  Re: Spel Code: Post_Validate error message depending on the category
    Best Answer

    Posted 05-22-2019 05:02 AM

    hi,

     

    based on what i understand, it could be:

     

    chg::z_validate_category(...) {
        if((category == "SIGSCLVM" || category == "SIGSCWVM" || category == "SIGSCPM") && (is_null(project))) {
            set_error(1);
            set_return_data(Project is REQUIRED);
            return;
        }
        if((category != "SIGSCLVM" && category != "SIGSCWVM" && category != "SIGSCPM") && (is_null(z_ttessa_code))) {
            set_error(1);
            set_return_data("TTESSA CODE REQUIRED");
            return;
        }
    }
    regards,
    pacy