CA Service Management

 View Only
Expand all | Collapse all

Change Parent Status When Child is Resolved

  • 1.  Change Parent Status When Child is Resolved

    Posted Jul 17, 2017 05:02 PM

    Hey guys,

     

    Im trying to do a customization to set the parent status to WIP when all the children are solved.

     

    For this, i create a condition macro with the code below:

     

    string wc;
    int active_count;
    wc = format("parent = '%s' AND status == 'RE'", persistent_id);
    send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "MLIST_STATIC", wc, -1,0);
    active_count = msg[1];
    logf(SIGNIFICANT, "%s",active_count);
    if (active_count < 0) {
    set_return_data(FALSE);
    }else
    {
    set_return_data(TRUE);
    }

     

    This condition macro was related to an event with a action macro that changes the ticket status to WIP with th code below:

     

    misc::change_ticket_status(this, group_leader, attached_event, event_tmpl, 'WIP');

     

    I've found in some of my searches a lot of stuff related to spel code, but I'm not very familiar with spel.

     

    Is there any way to do this customization in a simple way or even using spel code?

     

    Many thanx!!



  • 2.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 07, 2017 09:10 AM

    I'm not sure about spel code but here's an example of a PAM process I wrote to solve that problem.

     



  • 3.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 08, 2017 02:39 PM

    Hi ElwynnMartin and TMACUL!!

     

    Many thanx for replying!

     

    Unfortunately this client does not have PAM in its architecture, which is why I am resorting to spel code to try to deliver the requested customization.



  • 4.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 07, 2017 02:36 PM

    HI diegolimabsb ,

     

     

    I  agree  with ElwynnMartin, It's better using CA PAM, you can see an example here PAM::. UpdateObject - Process Example .

     

    Summary CA Process Automation 

     link_C#.zip 

     

    Regards



  • 5.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 08, 2017 02:12 AM

    create settowip.mod file with the following content

    OBJECT cr {
     TRIGGERS {
      POST_VALIDATE set_to_wip() 10024  FILTER( EVENT("INSERT UPDATE") && status{->RE} );
     };

    };

    create settowip.spl file:

    cr:set_to_wip(...)
    {
     string wc;
     int active_count;
     wc = format("parent = '%s' AND status != 'RE' AND status != 'CL' ", persistent_id);
     send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "MLIST_STATIC", wc, -1,0);
     active_count = msg[1];
     logf(SIGNIFICANT, "%s",active_count);
     if (active_count > 0) {
     return;
     }else
     {
       uuid who; 
      send_wait(0,top_object(), "call_attr", "cnt", "current_user_id"); 
      who=msg[0]; 
      send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, parent.persistent_id, "All Children resolved", "crs:5208"); 
      if (msg_error()) {   
      logf(ERROR,"Error %s",msg[0]);   
      }  

     }
    }

     

    Recycle SDM Services. I did not tested this code so if something goes wrong just remove those files and recycle services



  • 6.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 08, 2017 02:59 PM

    Hi Gutis!

     

    Thanx for your reply!

     

    Well, I do not know if I'm doing something wrong, since I'm not very familiar with spel code, but when creating the two files and performing tests creating a parent request, associating a child with it and defining its status as "solved", the status of the parent ticket was not changed to WIP.

     

    I did some searching in the STDLOG file but couldn' t find any errors connected to the newly created SPEL and MODS files.

     

    I've tried modifying some variables from line 4, modifying the status constraint to something like:

     

    wc = format ("parent = '% s' AND status = 'RE'", persistent_id);

     

    But even doing some tests of the type did not succeed in changing the status of the parent ticket.

     

    These files should be created in the C:\Program Files (x86)\CA\Service Desk Manager\site\mods\majic folder, right?

     

    The mods and spl files:

     

    • set_to_wip.mods
    OBJECT cr {
    TRIGGERS {
      POST_VALIDATE set_to_wip() 10024  FILTER( EVENT("INSERT UPDATE") && status{->RE} );
    };
    };

     

    • set_to_wip.spl
    cr::set_to_wip(...){
    string wc;
    int active_count;
    wc = format("parent = '%s' AND status != 'RE' AND status != 'CL'", persistent_id);
    send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "MLIST_STATIC", wc, -1,0);
    active_count = msg[1];
    logf(SIGNIFICANT, "%s",active_count);
    if (active_count > 0) {
    return;
    }else
    {
      uuid who; 
      send_wait(0,top_object(), "call_attr", "cnt", "current_user_id"); 
      who=msg[0]; 
      send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, parent.persistent_id, "All Children resolved", "crs:5208"); 
      if (msg_error()) {   
      logf(ERROR,"Error %s",msg[0]);   
      } 
    }
    }

     

    Thanx again for the help, Gutis!



  • 7.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 08, 2017 05:05 PM

    I try triggered the set_to_wip.spl file on the wsp.mods file but did´t work too!



  • 8.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 09, 2017 01:17 AM
     logf(SIGNIFICANT, "%s",active_count); 

    Should return active ticket count in the log. Could you check if there is such entry?



  • 9.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 09, 2017 01:18 AM

    Could you also provide code for status solved, because in trigger i have used code of status Resolved (RE)



  • 10.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 09, 2017 12:13 PM

    Hi Gutis,

     

    I read the entire code patiently and realized that I saved the file with the trigger as set_to_wip.mods (with s at the end) after correcting the file extension and inserting an apostrophe between the status RE on line 3 (as shown below), the  SPEL code worked changing the status of the parent ticket to WIP:

     

    POST_VALIDATE z_set_to_wip () 18 FILTER (EVENT ("INSERT UPDATE") && status {-> 'RE'});

     

    The only problem now is that the status of the parent ticket is changed anytime the child is resolved.

     

    Is it possible that the status change to be performed only when all children have their status changed to RE?

     

    In line 6 of the set_to_wip.spl file the attribute active_count = msg [1], does it refer to some kind of array of child tickets?

     

    The parent status is being changed correctly, the only problem is to tirggered the parent status change only when all child tickets are resolved.

     

    Im very grateful for all the help, Gutis!



  • 11.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 14, 2017 03:05 AM

    Hi,

    active_count = msg[1];

    should have number of active child tickets that are not in status resolved and closed

     wc = format("parent = '%s' AND status != 'RE' AND status != 'CL'", persistent_id);

    could you checl log file since  logf(SIGNIFICANT, "%s",active_count); should print this count in to log file

     

     



  • 12.  Re:  Change Parent Status When Child is Resolved

    Posted Aug 14, 2017 06:10 PM

    Hi Gutis!

     

    I did some more testing and the status of the parent ticket is changed when any of the children is resolved.

     

    In my tests I tried to "comment" in what I believe to be the attributes of the children list, to see what could happen, and parent is being changed to WIP even with 2 or 3 other children with status = OP.

     

    It seems that the part of the code that structures the child relationship (I believe) it is not being interpreted or has some error that I could not identify.

     

    "Commenting" (or not commenting) the attributes and codes below, the status of the parent ticket is changed when the first ticket of the child relationship is resolved.

     

    The commented code, which runs exactly like the code without the comment:

    cr::z_set_to_wip(...){
    string wc;
    int active_count;
    wc = format("parent = '%s' AND status != 'RE' AND status != 'CL'", persistent_id);
    //send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "MLIST_STATIC", wc, -1,0);
    //active_count = msg[1];
    //logf(SIGNIFICANT, "%s",active_count);
    //if (active_count > 0) {
    //return;
    //}else
    //{
      uuid who; 
      send_wait(0,top_object(), "call_attr", "cnt", "current_user_id"); 
      who=msg[0]; 
      send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, parent.persistent_id, "All Children resolved", "crs:5208"); 
      if (msg_error()) {   
      logf(ERROR,"Error %s",msg[0]);   
      } 
    }
    //}

     

    Unfortunately I also can not see any errors in the log files that could help me figure out where the error is.

     

    Many thanks again for the hepl!



  • 13.  Re:  Change Parent Status When Child is Resolved
    Best Answer

    Posted Aug 18, 2017 01:46 AM

    Try this code:

     

    cr::set_to_wip(...){
     string wc;
     int active_count; 
     wc = format("parent = '%s' AND status != 'RE' AND status != 'CL'", parent.persistent_id);
     send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "MLIST_STATIC", wc, -1,0);
     active_count = msg[1];
     logf(SIGNIFICANT, "Active Childs found %s",active_count);
     if (active_count > 1) {
     return;
     }else
     {
      uuid who; 
      send_wait(0,top_object(), "call_attr", "cnt", "current_user_id"); 
      who=msg[0]; 
      send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, parent.persistent_id, "All Children resolved", "crs:5208"); 
      if (msg_error()) {   
      logf(ERROR,"Error %s",msg[0]);   
      } 
     }
    }



  • 14.  Re:  Change Parent Status When Child is Resolved

    Posted Sep 13, 2017 01:52 PM

    Hi Gutis!

     

    Many thanks for your support and patience!

     

    It worked perfectly!

     

    Thanks again!