CA Service Management

Expand all | Collapse all

Compare field and logged user by Site-defined Condition Macro

Jump to Best Answer
  • 1.  Compare field and logged user by Site-defined Condition Macro

    Posted 12-21-2015 03:26 PM

    Hello Community Members!

    Is possible make a compare between a field and the logged user by Site-defined Condition Macro, as we do on Data Partition?

     

    For example:  customer IN @root.id

     

    I've tried this but doesn't work.

     

     

    Thanks in advance.



  • 2.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-21-2015 03:52 PM

    I think it may be possible in condition macro but definetly not in site defined condition. Of course it my depend on what you need to achive, for example for notifications you can use log_agent attribute to get id of the user that performed an action that initiated activity notification



  • 3.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-21-2015 05:36 PM

    How is this Macro being triggered? In the case of it being triggered by an event then it is being executed at the server level and there is no current logged-in user.



  • 4.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-22-2015 06:01 PM

    As far as i understand all macros are executed on server level by particular spel method that is called "execute". The only difference is in AA mode since events are always executed on background server. But anyway all macros are executed in context of particular user.



  • 5.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-22-2015 08:29 AM

    Hi Lindsay and Gutis,

     

    This Site-defined Condition Macro will be use as a Condition for changing status (Status Transitions).

     

    We have some specifics requirements for status transition. One of them is allow the transition from status.code "WIP" to "CL" only by the customer. We created a button to permit the customer close your Call_Req anytime (in case of solution by himself). But only the customer defined on ticket can do that.

     

     

    Thank for attention.



  • 6.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-22-2015 10:16 AM

    Then you can do it only using condition macro.



  • 7.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-22-2015 11:10 AM

    This is my problem. We prefer do not customize because the Administration is in charge for another team.

    But, if we have no choice, do you have an idea how can I compare? What I use to compare logged user: "@root.id" , "@cst.id" ? Do you have a template?



  • 8.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-22-2015 04:07 PM
    uuid who;
    string cntid;
    send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
    who=msg[0];
    cntid= format("%s",who);
    if (requested_by== cntid) {
    set_return_data(TRUE);
    } else {
    set_return_data(FALSE);
    }
    


  • 9.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-22-2015 04:20 PM
      |   view attached

    I have attached macro file you can load it using pdm_load utility, since it will generate new ID's for macro

    pdm_load -i -m -f macro.txt

    if possible test it on your testing enviroment first.

    Macro name:

    requested_by equal LogedIn User

    Attachment(s)

    zip
    macro.txt.zip   543 B 1 version


  • 10.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-28-2015 11:19 AM

    Hi Gutis,

    I have tried the macro but it doesn't works. I received the following log:

     

    12/28 14:12:15.40 V120H005       spelsrvr             6608 ERROR        pcexec.c              6201 Spell interp failed at  (...) (CUSTOM) ATT (exclusivo) - Cond p/ encerramento do TKT 2:9: Math argument type mismatch

    12/28 14:12:15.41 V120H005       spelsrvr             6608 ERROR        cr.spl                 428 Transition from 'Em andamento' to 'Fechada' failed condition macro macro:400855 - REJECTING

     

    On our DEV Environment, the Condition Macro has become this (I changed the requested_by attribute to customer):

     



  • 11.  Re: Compare field and logged user by Site-defined Condition Macro
    Best Answer

    Posted 12-29-2015 03:48 AM

    Hi, for the customer field try to change macro in the following way:

     

    uuid who;
    string cntpersid, cntpersid2;
    send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
    who=msg[0];
    cntpersid = format("cnt:%s",who);
    if (customer.persistent_id == cntpersid) {
    set_return_data(TRUE);
    } else {
    set_return_data(FALSE);
    }
    

     

     

    But first of all i would suggest you to try solution that was provided by Brett.Zipkin. From my point of view it should work without any problem.



  • 12.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-29-2015 12:04 PM

    Thank you Gutis!

    That last code worked fine. When you come to Brazil I will pay a beer!



  • 13.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-29-2015 02:01 PM

    Looking forward to have some beer in Brazil :)



  • 14.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-22-2015 05:33 PM

    If you want to allow only the customer to change the status of the ticket to 'CL' then use a Data Partition Constraint:

     

    Table_Name: Call_Req

    Constraint Type: Pre-Update

    Error Message: Only the Affected End User is allowed to close the ticket.

    Constraint: status != 'CL' OR (status = 'CL' AND customer = @root.id)



  • 15.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-22-2015 05:53 PM

    Lindsay, i think this constrain will restrict them from editing it once it is closed, but they will be able to change status to closed. So constraint type should be Update. But anyway this will ban them from changing to closed from any status.



  • 16.  Re: Compare field and logged user by Site-defined Condition Macro

    Posted 12-24-2015 09:54 AM

    You can do it with Site Defined Macro.  I do something similar to that today but I check the access type of the person making the update.  I created a new Activity Association using last_mod_by.access_type.   Then using Site Condition, I compare that new item to a fixed value in my case for True/False.

     

    For yours you can probably just use last_mod_by without the dot walking.  Then compare it to the field Affected User for true false.

     

    When you perform an activity, like update status, the last_mod_by field on the main ticket is the currently logged in user.  I've tested this in Status transitions to only allow Change Managers to move certain statuses so I know the field value can be checked before the official save.  Give it a shot.