CA Service Management

  • 1.  How to insert "previous and current values" from a custom table in a log table (also custom) with spel code

    Posted Nov 05, 2018 09:34 AM

    CA Service Desk Manager

    ________________________________________________________________________

    Hello, I'd like somebody help me with this...


    I need register in "zLog_Values" table every change made in some fields of "zValues" table, using spel code

    I have two custom tables: "zLog_Values" and "zValues".


    The "zValues" fields are:


    -cr_persid (SREL to cr table)
    -chg_persid (SREL to chg table)
    -value1
    -value2
    -value3

     

    I need register in "zLog_Values" table the following values from zValues table and the current session:

     

    -Contact name who is making the change in the field (connected user)
    -Modification date (current date)
    -Current value (fields= value1, value2, value3)
    -New value entered by the user(fields= value1, value2, value3)
    -Request/Incident/Problem/Change persid

     

    Thanks in advance,

    Ana KBS.



  • 2.  Re: How to insert "previous and current values" from a custom table in a log table (also custom) with spel code

    Posted Nov 05, 2018 08:41 PM

    Hi,

     

    You can can use the spel api method insert_object  to create entries in this customs table. Also, instead of creating two columns with relationships to chg and cr I suggest creating one column called object and storing the persistent_id of the foreign object as a string. One reason for this is the foreign key for the chg table is id but the foreign key for cr is persistent_id.

     

    Let is know if you need help with the trigger/script.



  • 3.  Re: How to insert "previous and current values" from a custom table in a log table (also custom) with spel code

    Posted Nov 05, 2018 08:50 PM

    Also, before you get too far into this. Have you looked at enabling kpi ticket data or investigated the audit log options? If either of those work for your use case they would be preferred.



  • 4.  Re: How to insert "previous and current values" from a custom table in a log table (also custom) with spel code

    Posted Nov 06, 2018 01:50 PM

    Thanks Grant! you're very kind!

    I will try what you suggest about the fields....

    Honestly, I have a bit experience building spel scripts/triggers, so, definetly I'll need help.

     

    I was read about audit log and kpi options but I think it will work only for OOTB tables.

    My concern also was how to obtain the previous value of the updated fields...and yesterday I found this link Save Previous Value to custom field  (made by you)

     

    Best regards!

     

    Ana KBS.



  • 5.  Re: How to insert "previous and current values" from a custom table in a log table (also custom) with spel code
    Best Answer

    Posted Nov 06, 2018 07:25 PM

    Hi Ana,

     

    You can access the previous value of an attribute when that attribute is passed as a parameter in a trigger. So for all the attributes you want to check you’ll need them added as parameters.

     

    cdtj explains this well here. How can I get the previous and current value of a field in a POST-VALIDATE TRIGGER? 



  • 6.  Re: How to insert "previous and current values" from a custom table in a log table (also custom) with spel code

    Posted Nov 07, 2018 12:40 PM

    Thank you so much! 

    I wll chedk that link as soon as I can.

    Regards!