CA Service Management

 View Only
  • 1.  Check if one element exist with Spel

    Posted Feb 23, 2016 02:37 PM

    Hi comunnity, i have an object witch haves a list that is relationed with other object using BREL relationship. Everything is working nice, but i need to check if exist the element before add a new one to the list. How can i do this?

     

    I created on my .mod file:

     

    OBJECT zdemand_aplicativos_list {

      TRIGGERS {

      PRE_VALIDATE verify_demand_app_list() 23332

      FILTER(

      EVENT("INSERT UPDATE")

      );

      };

    };

     

    This fires when the user push the "Save" button.

    But i down know exactly how to check if this register exists.



  • 2.  Re: Check if one element exist with Spel

    Posted Feb 23, 2016 03:35 PM

    HI, your trigger will not do any without your verify_demand_app_list spl code

    Can you share it? and explain a little more what you are trying to archive?

    You can retrieve values in your spl using a sync_fetch but if you just want to avoid duplicate theis can be done flag the correct option for your corresponding attributes in the schema designer.

    Hope this help.

    /J



  • 3.  Re: Check if one element exist with Spel
    Best Answer

    Posted Feb 25, 2016 09:30 AM

    Hi friends, i resolve this using this:

     

    on the .mod file:

    OBJECT zdemand_aplicativos_list {

      TRIGGERS {

      PRE_VALIDATE verify_demand_app_list() 23332

      FILTER(

      EVENT("INSERT UPDATE")

      );

      };

    };

     

    on the .spl file:

    zdemand_aplicativos_list::verify_demand_app_list(...)

    {

      uuid who;  

      send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");  

      who=msg[0]; 

      send_wait(0, top_object(), "call_attr", "api", "get_list", "zdemand_aplicativos_list", who, format("zdemand_id = %s AND zdemand_aplicativo_id = %s AND delete_flag = 0", zdemand_id,zdemand_aplicativo_id), -1);  

      if (msg_error()) {  

      printf("Error %s",msg[0]);  

      }  

      else  

      { 

       int count;

       object obList; 

       count = msg[1]; 

       obList = msg[0]; 

       printf(msg[1]);

       if(count > 0){

         logf(SIGNIFICANT, "Ya existe el aplicativo en la lista, aparece un total de: %s veces.", count);

      set_error(1);

      set_return_data("Error: Ya este elemento existe en la lista");

      return;

       }

      }

    }

     

    Using this guide: get_list

    Thanks!!



  • 4.  Re: Check if one element exist with Spel

    Posted Feb 25, 2016 10:09 AM

    yes sync_fetch anf get_list mostly do the same,  get list be the newer method

    Glad you fix it on your own. always better

    /J