CA Service Management

Expand all | Collapse all

Using SPL code to evaluate Change field form

Jump to Best Answer
  • 1.  Using SPL code to evaluate Change field form

    Posted 11-12-2018 11:12 AM

    I have this request in the change form:

    I have the category field and the root cause fields.

    Some categories of development area need a root cause and others areas doesn´t need it.

    I want that when the user clics the save button in order to create a change order, the function evaluates than if the category field is fill with a development category and the root cause is blank, display a message warning that if "you choose this category it must be set with a root cause, in others cases it will be ok (for example if  the category is another accepts or not a root cause)"

     

    This is my function I want to achive with spl code:

     

    file.mod

    MODIFY chg {PRE_VALIDATE zValidateRootCause() 4200 FILTER(EVENT("INSERT"));};

     

    file.spl

    chg::zValidateRootCause(...) {
    string zmsgA21;
    {
    if (category == '401314' && rootcause == '' ) {
    zmsgA21=format("For this category must be a select a root cause",chg_ref_num,requestor);
    set_error(1);
    set_return_data(zmsgA21);
    return;
    }
    }
    }

     

    But when I create a change order of development area, the function doesn't evaluate the values I put on the respective fields. Root cause (Causa raíz) field is in blank and Category (Categoría) field is set with the name of development category "GD.Desarrollo". The number 401314 used on the validate function is the id of the category in the chgcat table from the mdb db.

     

     

     

    What am I doing wrong?

    I dont' know if I can do this directly in the regular form Detail_chg.htmpl

     

    Thanks for the help you cand provide.

     

    Regards

    Carlos Ramirez

     

    #sdmfields

    #sdm

    #servicedesk14.1

    #spel

    #spelcode

    #changeorderworkflow



  • 2.  Re: Using SPL code to evaluate Change field form

    Posted 11-12-2018 01:24 PM

    What you need to know is that there is an object layer in SDM and SPEL code runs against it, not against the DB itself.

     

    You need to check the object CHGCAT and look for the relation attribute :

     

     

    It means that this attribute is used for relation so you need to use this one when comparing a foreign key.

     

    In "chg" object, the attribute "category" is a foreign key to "chgcat". Wich means that "category" contains the "code" of a "chgcat" object!



  • 3.  Re: Using SPL code to evaluate Change field form

    Posted 11-13-2018 07:24 AM

    Good day Pier,

     

    I understand that I have the chgcat table from the schema designer:

     

     

    So, I have to use in the spl code like this for example:

     

    file.spl

    chg::zValidateRootCause(...) {
    string zmsgA21;
    {
    if (category.code == '401314' && rootcause == '' ) {
    zmsgA21=format("For this category must be a select a root cause",chg_ref_num,requestor);
    set_error(1);
    set_return_data(zmsgA21);
    return;
    }
    }
    }

     

    Or how I should write the condition ? in order to tell the user that if would like to use this category, he has to put a root cause in the corresponding field.

     

    Thanks for the help you can give me.

     

    Regards,

    Carlos Ramirez



  • 4.  Re: Using SPL code to evaluate Change field form

    Posted 11-13-2018 08:52 AM

    It looks to me that you do not understand Relational databases.

     

    A relational database means there is relations.

     

    A foreign key is a column in a table that store a value that identifies a row in another table.

     

     

    In your case, you are in the object layer but it behave almost like a relational database. The object "chgcat" says that its relational attribute (Campo clava externa) is "code".

     

    It means that the value in "code" is used to reference a a specific "chgcat" object in other object.

     

     

    So it you followed me, in "chg" object, there is an attribute that is a foreign key. It holds a value coming from "chgcat" object. Since "chgcat" object relational attribute is code, it means that "category" in "chg" holds a "code" value.

     

     

    So let's say you have a Change Category named "IT Change" with a code "itchg",

     

    The condition will be : if (category == 'itchg' && rootcause == '' ) 



  • 5.  Re: Using SPL code to evaluate Change field form
    Best Answer

    Posted 11-13-2018 11:24 AM

    Good day Pier,

     

    Thanks for the information. Finally got what you mean about the objects and in this case only I have to do is to check the code of the category in Service Desk and not in the database as I was doing at the beginning. I look for the code of the category I want to use for the condition in the category list section and got this:

     

     

    I evaluate the condition when I create (insert) or update a change order.

    So in the spel code I want to do will be like:

     

    chg::zValidaCausaRaiz(...)
    {
    string zmsgA21;
    string Evento;
    {
    Evento = event();
    if (Evento == "INSERT" || Evento == "UPDATE") {
       if ( (category == 'DESA.DESP') && (is_null(rootcause)) {

          logf(SIGNIFICANT, "categoria:: [%s] [%s]", chg_ref_num, category);
          zmsgA21=format("Para este tipo de categoria se debe seleccionar una Causa Raiz",chg_ref_num,requestor);
          set_error(1);
          set_return_data(zmsgA21);
          return;
       }
    }
    }
    }

     

    With this code I finally obtain what I want to do with the development category.

    Thanks for the help Pier,

     

    Regards,

    Carlos Ramirez