Menu

Change ticket state on public log update

Rie Ann
2023-11-29
2024-02-09
  • Rie Ann

    Rie Ann - 2023-11-29

    Good day! Is there any option to automatically update the ticket state when public log is updated? For example, a user updated the public log of a ticket that is in pending state, I want it to automatically moved to assign state.
    Thank you!

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2023-11-29

    Check out the "apply stimulus". You'll probably be looking for something like "ev_assign" or "ev_reassign".

     
  • Vincent @ Combodo

    If the ticket was updated through Mail, there is a mailbox configuration field to define the stimulus to apply on ticket update by email.
    If the ticket was updated directly in the portal, then you need to code something like this, in an extension

     UserRequest::protected function OnUpdate()
      {
          parent::OnUpdate();
          if (ContextTag::Check('Portal:itop-portal') && ($this->Get('status') === 'pending')) {
                  $oLog = $this->Get('public_log');
                  if ($oLog->GetModifiedEntry('html') != '')
                  {
                      $this->ApplyStimulus('ev_assign');
                  }
          }
      }
    
     
    👍
    2
    • Rie Ann

      Rie Ann - 2023-11-30

      Hi thank you for this, it is very helpful. Tho I have a follow up question. I want to know that the user who updated the public log is the caller. I have this code but it is now working because the GetKey() is not returning an int. Or i am not sure if that is the problem.

      if ($oPublicLog->GetModifiedEntry('html') != '') {
                      $publicLogUpdates = $this->Get('public_log');
                                          if ($publicLogUpdates != null) {    
                                              $publicLogUpdates = $publicLogUpdates->GetAsArray();
                                              $lastPublicLogUpdate = reset($publicLogUpdates); 
                                              $updateAuthorName =  $lastPublicLogUpdate['user_login'];
                                              // get id of user who last posted in public log
                                              $updateAuthorUserID =  $lastPublicLogUpdate['user_id'];
                                              // convert string to int
                                              $updateAuthorUserID = intval($updateAuthorUserID);
                                              //var_dump($updateAuthorUserID);
      
                                              $sTicketCallerId = $this->Get('caller_id');
                                              //var_dump($sTicketCallerId);
                                              $oUserAccount = new DBObjectSet(DBObjectSearch::fromOQL("SELECT UserLDAP WHERE contactid=$sTicketCallerId"));
                                              //var_dump($oUserAccount);
                                              if ($oUserAccount->Count() > 0) {
                                                  // get person id of user account
                                                  $oUserAccount = $oUserAccount->ToArray();
                                                  $oUserAccount = reset($oUserAccount);
                                                  $userAccountId = $oUserAccount->GetKey();
                                                   var_dump($userAccountId);
                                                  // var_dump($sTicketCallerId);
                                                  //throw new Exception("updated");
      
      
                                                  if ($updateAuthorUserID == $userAccountId) {
                                                      var_dump($updateAuthorUserID);
                                                  //  $this->ApplyStimulus('ev_assign');
                                                  }
                                              }
      
                                          }
                                   }
      
       

      Last edit: Rie Ann 2023-11-30
  • Vincent @ Combodo

    I'd recommend to allow the code to see all data, otherwise, the method is executed with the rights of the current user, who is not allowed to see the User class.

    $oUserAccount->AllowAllData();
    

    But if you performed the test with an admin user, you can't see the issue.
    In which case there must be another error

     
    👍
    1

    Last edit: Vincent @ Combodo 2023-11-30
    • Rie Ann

      Rie Ann - 2023-12-01

      Hi, thank you so much. This resolve the issue now. However, after successfully assigning, the TTR deadline is now missing. Is there any reason why it is not showing? It just stays blank, I don't think it inherits the value of the previous TTR. Thanks!

       
  • Aydin Özgün

    Aydin Özgün - 2024-02-08

    Hi, i'm also at this point with TTR. Can someone help or give a tip here? Best regards, Aydin

     
  • Aydin Özgün

    Aydin Özgün - 2024-02-09

    Using OnUpdate, the TTR deadline Stopwatch does not work when updating the ticket from the UserPortal. With AfterUpdate, the TTR deadline is correctly displayed again after a status change from Pending to Assigned!

    <method id="AfterUpdate" _delta="define">
            <static>false</static>
            <access>protected</access>
            <type>Overload-DBObject</type>
            <code><![CDATA[
            protected function AfterUpdate() 
            {
                parent::AfterUpdate();
                if (ContextTag::Check('Portal:itop-portal') && ($this->Get('status') === 'pending')) {
                    $oLog = $this->Get('public_log');
                    if ($oLog->GetModifiedEntry('html') != '')
                    {
                      $this->ApplyStimulus('ev_assign');
                    }
                }
            }]]></code>
    </method>
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.