CA Service Management

 View Only
Expand all | Collapse all

How can I get the previous and current value of a field in a POST-VALIDATE TRIGGER?

  • 1.  How can I get the previous and current value of a field in a POST-VALIDATE TRIGGER?

    Posted Jun 06, 2018 07:43 AM

    Hi,

    i'm trying to implement a POST-VALIDATE TRIGGER for the CR table and i need to compare the previous and current values of some attributes.

     

    Example 1: (In this case I know how to do it)

    ... test.mod ...

    OBJECT cr {
    TRIGGERS {
    POST_VALIDATE zupdate_cr(group) 153 FILTER(EVENT("UPDATE") && group{});
    };
    };

     

    ... test.spl ...

    cr::zupdate_cr(...)
    {
    uuid previous_group, current_group;

    previous_group= argv[2];
    current_group= argv[3];

    .

    .

    .

    }

     

    But if there are more than one attributes changed i don't know how do it.

    Example 2:

    ... test.mod ...

    OBJECT cr {
    TRIGGERS {
    POST_VALIDATE zupdate_cr() 153 FILTER(EVENT("UPDATE") && (group{} || status{}));
    };
    };

     

    ... test.spl ...

    cr::zupdate_cr(...)
    {
    uuid previous_group, current_group;

    strion previous_status, current_status

     

    previous_group=  ?;
    current_group=  ?;

    previous_status= ?;

    current_status= ?;

    .

    .

    .

    }

    I need to know how to obtain the values of previous_status, current_status, previous_group and current_group.

    Can somebody help me?

    Thanks.



  • 2.  Re: How can I get the previous and current value of a field in a POST-VALIDATE TRIGGER?

    Posted Jun 06, 2018 07:48 AM

    When you add additional attributes the argument value always increments by 3. Argv[0] is the number of attributes passed, argv[1] is the name of the first attribute, argv[2] is the previous value of the first attribute, argv[3] is the new value of the first attribute, argv[4] is the name of the 2nd attribute, argv[5] is the previous value of the 2nd attribute, argv[6] is the new value of the 2nd attribute, and so on...

     

     

    ... test.spl ...

    cr::zupdate_cr(...)
    {
    uuid previous_group, current_group;

    strion previous_status, current_status

     

    previous_group= argv[2];
    current_group= argv[3];

    previous_status= argv[5];

    current_status= argv[6];

    .

    .

    .

    }



  • 3.  Re: How can I get the previous and current value of a field in a POST-VALIDATE TRIGGER?

    Posted Jun 08, 2018 04:09 AM

    Thanks



  • 4.  Re: How can I get the previous and current value of a field in a POST-VALIDATE TRIGGER?
    Best Answer

    Posted Jun 06, 2018 08:29 AM

    hi,

    you need to pass attr as function argument. try to use logf to display all input args:

    POST_VALIDATE zupdate_cr(group, status) 153 FILTER(EVENT("UPDATE") && (group{} || status{}));
    cr::zupdate_cr(...) {
              int msg_i;
              for (msg_i = 0; msg_i < argc; msg_i++) {
                   logf(SIGNIFICANT, "argv[%d]: %s", msg_i, argv[msg_i]);
              }
    }

     

    output will be in this format:

    0: input attrs count
    1: attr name
    2: prev value
    3: new value
    4: attr name
    5: prev value
    6: new value
    ... and so on
    n+1: attr name
    n+2: prev value
    n+3: new value

     

    regards



  • 5.  Re: How can I get the previous and current value of a field in a POST-VALIDATE TRIGGER?

    Posted Jun 06, 2018 08:48 AM

    Thank you very much! It's exactly that i'm looking for!