CA Service Management

Expand all | Collapse all

How to terminate action via spel macro without displaying error?

  • 1.  How to terminate action via spel macro without displaying error?

    Posted Dec 29, 2015 08:18 AM

    Hi team,

    I have complex LREL tables with multiple columns,

    on each inserting I'll checking data and if it matches some patterns new data are merging with existing,

    otherwise it completes without any actions.

     

    My current algorithm looks like:

    if (<some pattern>) {
         <merge data>;
         set_error(1);
         set_return_data("Merge complete");
    } else {
         <do nothing>
    }
    

    this works as defined but on each merge it shows error message, which can dissapoint other admins.

     

    So I'm looking a way how to prevent inserting and break operation without error message.

     

    Regards,

    cdtj



  • 2.  Re: How to terminate action via spel macro without displaying error?

    Broadcom Employee
    Posted Jan 05, 2016 04:39 AM

    Hi,

     

    Did you try writing a return; statement in place of code below:

     

    set_error(1); 

    set_return_data("Merge complete");

     

    Regards,

    Kavya



  • 3.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 05, 2016 01:21 PM

    thank you for the reply,

    but adding return didn't make any change



  • 4.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 05, 2016 06:21 AM

    You'll have to get rid of the

    set_error(1);

    and while you're at it you can also drop the else block if it doesn't do anything. Not sure if you can just go and delete it but that statement is specifically setting the error flag to 1 and if you don't want errors, don't set the flag



  • 5.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 05, 2016 01:24 PM

    I used "else" block only for explain how logic were implemented real code is differ.

    I'm using set_error function only for break current operation, otherwise I'll get data insert which is unwanted.



  • 6.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 06, 2016 02:01 AM

    I see. I assume you're doing this on PRE_VALIDATE or POST_VALIDATE, so would it be possible to cancel the checkout of the object being created and modify the dobs you want to merge with manually, like you already do? So something like

    if (<your condition>) {
        object gl;
        send_wait(0, top_object(), "get_co_group");
        // Add error handling for send_wait here
        gl = msg[0];
        send_wait(0, gl, "uncheck");
    
        // Do the manual merge here
    
        set_return_data("Merge complete");
    } else {
        <rest of your stuff>
    }
    
    
    

    I reasoned you have the dob checked out so you should be able to cancel the checkout and then do the stuff you already do anyway. Give it a shot and be aware the above snippet is pseudo in the best case, didn't run it through the interpreter in any form.



  • 7.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 06, 2016 06:23 AM

    Great idea, Jussi,

    i'll try it soon,

    but not very soon because in our country we have new year vacations till 11 Jan



  • 8.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 06, 2016 07:18 AM

    Well, happy new year then

    Let us know the results, I'm actually interested to know if it is possible to cancel the creation without reverting to an error state.



  • 9.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 11, 2016 04:41 AM

    well, I tried, bad news: this method didn't work,

    a good one: i found a way how to get current group_leader but i dont have an idea how to use this

    code:

    send_wait(0, this, "get_gl");

    for (i=0;i<msg_length();i++) {

      logf(SIGNIFICANT, "msg[%d]: %s", i, msg[i]);

    }

    group_leader = msg[0];

    send_wait(0, group_leader, "uncheck");

    for (i=0;i<msg_length();i++) {

      logf(SIGNIFICANT, "msg[%d]: %s", i, msg[i]);

    }

    result:

    z_gts.spl               14 msg[0]:

    top_ob.c              4121 Internal error in uncheck for oTkAAA - status 6 is not IDLE

    z_gts.spl               19 msg[0]: AHD03027:Internal error in uncheck

    top_ob.c              4027 Got msg with type set to 0

    regards,

    cdtj



  • 10.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 11, 2016 05:20 AM

    Did you try with

    send_wait(0, top_object(), "get_co_group");
    

    to get the group leader or just with the snippet you pasted? I have no idea if it makes any difference but I'm out of fresh ideas



  • 11.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 11, 2016 05:40 AM

    This will not give a trick

    because object that triggers spel macro via .mod file is already predefined as this object and checked out in this.group_leader, and cannot be checked out twice.



  • 12.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 13, 2016 06:13 AM

    Hi
    I still don't understand the whole picture, unfortunately.
    But when code is executed in a pre validate or post validate trigger, the group leader of the actual object is already in a checkin phase. That means you are not able to check out additional objects in this phase or able to uncheck current transactions with this group leader as far as I know.
    As said before, what exactly do you try to achieve? You first code snippet is just to less for me to understand your challenge.
    Regards
    ......Michael



  • 13.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 13, 2016 07:04 AM

    Hi Michael,

     

    Followed scenario might be illogical or partially offensive, but this is what I have, so, i'm sorry

     

    I have table to keep list relations (LREL) that contains data from 4 different tables (nr/pcat/isscat/chgcat),

    I'm validating data on list update,

    for example I'm updating relation between nr and pcat,

    then macro compare pcat with isscat and chgcat by sym.

    After all procedures I receive new data row which contains my initial inputs: nr and pcat, and compared chgcat and isscat, if they were found.

     

    But if I create new category (or make it active) and try to insert it in that relation, I'll receive data duplication.

    This is why I check each inserting and merge data if it match existing data.

     

    Here is simplier scenario where described method could be used:

    - customer creates Request;

    - system checks Customer, Category and Description (for example);

    - if all data are matching already opened ticket:

    - - system creates Activity Log about repetaed appeal;

    - - system don't create new ticket but display to customer success message.

     

    My current code part looks like:

    if (!is_null(in_chg)) {
        send_wait(0, top_object(), "call_attr", "chgcat", "val_by_key", "code", in_chg, 1, "persistent_id");
        send_wait(0, top_object(), "call_attr", "chgcat", "dob_by_persid", 0, msg[1]);
        new_chgcat = msg[0];
        wc = format("nr IN (U'%s') AND (isscat.sym IN '%s' OR pcat.sym IN '%s')", nr, new_chgcat.sym, new_chgcat.sym);
        logf(SIGNIFICANT, new_chgcat.sym);
        send_wait(0, top_object(), "call_attr", "z_nr_cat", "sync_fetch", "STATIC", wc, -1, 0);
        zcount = msg[1];
        logf(SIGNIFICANT, "found: %d [%s]", zcount, wc);
        if (zcount == 1) {
            logf(SIGNIFICANT, "Merging data [%s]", new_chgcat);
            send_wait(0, new_chgcat, "get_attr_vals", 1, "REL_ATTR");
            macro::upd_val("z_nr_cat", wc, 3, 15, "chgcat", msg[3]);
            break_op = 1;
        } else if (zcount > 1) {
            logf(ERROR, "Unable to merge [%d] items. Search string [%s].", zcount, new_chgcat.sym);
        } else {
            send_wait(0, top_object(), "call_attr", "isscat", "val_by_key", "sym", new_chgcat.sym, 1, "REL_ATTR");
            if (msg_length() > 1) {
                send_wait(0, this, "call_attr", "isscat", "set_val", msg[1], "SURE_SET");
            }
            send_wait(0, top_object(), "call_attr", "pcat", "val_by_key", "sym", new_chgcat.sym, 1, "REL_ATTR");
            if (msg_length() > 1) {
                send_wait(0, this, "call_attr", "pcat", "set_val", msg[1], "SURE_SET");
            }
        }
    }
    if (break_op) {
        set_error(1);
        set_return_data("Data merged successfuly!");
    }
    


    Best regards,

    cdtj



  • 14.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 13, 2016 04:05 PM

    Hi cdtj,

    hm, now its getting a bit clearer.

    So, this is my understanding.

    Your codesnippet is part of pre or post validate trigger off the z_nr_cat factory, which gets fired when a new z_nr_cat object gets created. Correct?

    And the real Thing you want to achieve is to bypass the creation if certain conditions are met, correct?

    I don't  know if this will work,but maybe deleting the current object may help

    send_wait(0,this, "dob_mark_delete");

    If this doesn't work because of the same reasons a checkout or uncheck is not possible, you may consider using attribute trigger instead.

    Which version of SDM are you running, 14.1 provides a new object trigger which may help here.

    Kind regards

    .....Michael



  • 15.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 14, 2016 01:35 AM

    Thank you for your reply Michael,

    you understood it right,

    I'll try to use dob_mark_delete,

    could you provide more info about "attribute trigger", do you mean ON_CI?

    I'm still on 12.7.

     

    Regards,

    cdtj



  • 16.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 14, 2016 02:20 AM

    You're welcome.

    As you may know already, object trigger can be used to add application logic whenever an object gets saved(checkin) like PRE_VALIDATE, POST_VALIDATE, POST_CI.

    Attribute trigger gets fired when attributes of an object are changed. The ones I have in mind are  ON_PRE_VAL and ON_POST_VAL.

    The advantage in these triggers is, that you are free to use the current group leader however you like, because the group ledaer is not in the checkin phase yet.

    So to start somewhere , I would define something like:

    MODIFY z_nr_cat chgcat ON_POST_VAL domerge( nr, chgcat, isscat, pcat ) FILTER(EVENT("INSERT"));

    and create a spl file with

    z_nr_cat.chgcat::domerge(...){

       int i;

       for(i=0;i<argc;i++) logf(SIGNIFICANT,"argv[%d]=%s",i,(string(argv[i]);

    }

    this code gets fired if there is an insert of a z_nr_cat object, and the chgcat attribute is changed(set). As you can see the arguments to this trigger are tripplets giving the old and new value of the specified attributes.

    You also have the this variable avaiable.

    Hope this helps a bit.

    kind regards

    ............Michael



  • 17.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 14, 2016 02:34 AM

    Sounds good,

    as I remembered I can't terminate object update with error (as exampeled in my code) while triggering macro from attribute,

    but seems that I can delete or uncheck object because it's not currently "in progress".

    Thanks!



  • 18.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 14, 2016 02:47 AM

    yep, give it a try



  • 19.  Re: How to terminate action via spel macro without displaying error?

    Posted Jan 14, 2016 04:41 PM

    Thank You, for sharing this information