Topic
3 replies Latest Post - ‏2014-03-31T22:31:55Z by StaceyRG
StaceyRG
StaceyRG
4 Posts
ACCEPTED ANSWER

Pinned topic How to add a comment, such as during a transition

‏2014-03-25T17:56:47Z |

I'd like to add a comment to the CR's transition log when making a transition. How is this done? Here's my automation code for transitioning one or more CRs to a new state. Would I modify the "status_log" data object? Would I use a setValue call with just the text I want to add to the log? Or would I do a getValue for the status_log, then setValue the old appended to the new? Or is there some other method used to add something to the log?

 

    foreach $cr_id (@$pa_objects) {
        my $scr = $csapi->GetCRData( $user, $cr_id, "crstatus" );

    # grab the valid transitions so we can translate that into a transition code
        my $x = 0;
        my %valid_transitions =
          map { $_->{mToState} => $x++ } @{ $scr->{myTransitions} };

        # check that the transition is valid
        if ( !defined( $valid_transitions{$next_state} ) ) {
            return $self->get_client->process_status( $ret, 'error',
                "Invalid state: $next_state" );
        }

        my $transition_code = $valid_transitions{$next_state};

        my $transition_data =
          $csapi->TransitionCRData( $user, $cr_id,
            $scr->getTransitionLink($transition_code)->getTransition() );
        $transition_data->getDataObjectByName("crstatus")
          ->setValue( $scr->getTransitionLink($transition_code)->getToState() );
        my $tmpstr = $csapi->TransitionCR( $user, $transition_data );

        if ( $tmpstr->{strResponseData} =~ m!Transition was successful! ) {
            my $message = "CR $cr_id was transitioned successfully";
            $self->get_client->process_status( $ret, 'debug', $message );
        }
        else {
            my $message = "CR transition failed: $scr";
            return $self->get_client->process_status( $ret, 'error', $message );
        }
    }

 

Updated on 2014-03-25T19:52:36Z at 2014-03-25T19:52:36Z by StaceyRG
  • DevM
    DevM
    9 Posts
    ACCEPTED ANSWER

    Re: How to add a comment, such as during a transition

    ‏2014-03-27T14:06:24Z  in response to StaceyRG

    Hi Stacey,

      I'm no expert, but here is the subroutine I generated to write comments to the transition_log:

    sub updateComment
    {
      # Receive Input
      my $crid = shift;
      my $newComments = shift;

      # Declare varibles
      my $tmp;
      my $tmpstr;

      #Declare Constants
      my $comment_loc = "_COMMENTS";

      # Get the object vector from CR
      $tmp = $csapi->GetCRData($user, $crid, "problem_number|$comment_loc");

      $tmp->getDataObjectByName($comment_loc)->setValue($newComments);
     
      # Update the CR
      $tmpstr = $csapi->ModifyCR($user, $tmp);
    }

     

    It takes the CRID of the CR you are writing to and the comment text as input. It writes directly to the _COMMENTS system attribute. I am running Rational Change 5.3. If your system has a different comments attribute you may need to change $comment_loc.

    Also, the subroutine itself makes no attempt to initalize contact with the database. But since you seem to be using the standard $csapi declarations it should work fine.

    I hope this helps,

       DevM

    • StaceyRG
      StaceyRG
      4 Posts
      ACCEPTED ANSWER

      Re: How to add a comment, such as during a transition

      ‏2014-03-27T18:56:00Z  in response to DevM

      This looks close to what I was hoping the solution would be: nice and simple. I'll try it out soon. Is there anywhere that _COMMENTS is documented?

    • StaceyRG
      StaceyRG
      4 Posts
      ACCEPTED ANSWER

      Re: How to add a comment, such as during a transition

      ‏2014-03-31T22:31:55Z  in response to DevM

      This worked. Thanks!