By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,426 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

How to disable history from perl code

P: 5
I am using a script. It autometically updates some cases. And it updates history of the cases also. But i don't want to be like that. I don't wnat to update history.
Is there any way to do.
Feb 21 '08 #1
Share this Question
Share on Google+
11 Replies


KevinADC
Expert 2.5K+
P: 4,059
No idea what you are even talking about.
Feb 21 '08 #2

Kelicula
Expert 100+
P: 176
Provide some code. Maybe we can help.
Include the "histories" you speak of.
Feb 22 '08 #3

P: 5
I am updating 2 fields with my script. I have sheduled the code to run it for every 1 hour. It is updating successfully. But it is also updating history for each record. So per a day 24 entry will be registering in history of cases. So that is my problem. I don't want history to update.
Expand|Select|Wrap|Line Numbers
  1. =pod
  2.  
  3. =head1 Due Counter update
  4.  
  5. This program is supposed to be called by the scheduled tasks scheduled repeadtedly with an apropriate
  6. time interval. The purpose is to find all trouble report with a certain state, and inctrement a counter 
  7. in each record. It needs the cqperl Perl interpreter that comes with the IBM Rational ClearQuest 
  8. distribution
  9.  
  10. =head2 Syntax
  11.  
  12. =begin html
  13.  
  14. <pre>
  15. cqperl duecounterupdate.pl
  16. </pre>
  17.  
  18. =end html
  19.  
  20. =cut 
  21.  
  22. my $USERNAME   = "sqluser";    # This user account is a hard-coded
  23. my $PASSWORD   = "xyz";    # user accouunt in the database with SQL run privileges
  24. my $REPOSITORY = "xyz";
  25. my $DATABASE   = "TEST";
  26. my @QUERIES    = (
  27.     [ "Answering_Time_Count", "Public Queries/Due Counter/all_errand_answering_time_cases" ],
  28.     [ "Delivery_Time_Count",  "Public Queries/Due Counter/all_solution_delivering_time_cases" ],
  29. );
  30. my $one_day = 24 * 3600;       # Number of seconds for one day
  31. require CQPerlExt;             # Must be run with the cqperl binary.
  32.  
  33. #   Log on to the schema repository
  34. my $sqlSession = CQPerlExt::CQSession_Build();
  35. eval { $sqlSession->UserLogon( $USERNAME, $PASSWORD, $DATABASE, $REPOSITORY ); };
  36. if ($@) {
  37.     print "$@\n";
  38.     exit;
  39. }
  40. print "SQL Login as $USERNAME on $REPOSITORY succeeded\n";
  41.  
  42. # Get all national holidays
  43. my %HOLIDAYS  = ();
  44. my $resultSet = $sqlSession->BuildSQLQuery("select fldcolumn from Holidays order by 1");
  45.  
  46. $resultSet->Execute();
  47. while ( $resultSet->MoveNext() == $CQPerlExt::CQ_SUCCESS ) {    
  48.     my $holiday = $resultSet->GetColumnValue(1);
  49.     $HOLIDAYS{ substr( $holiday, 0, 10 ) } = 1;
  50. }
  51.  
  52. #print "Found holidays: " . join( ",", keys %HOLIDAYS ) . "\n";
  53.  
  54. my $workspace = $sqlSession->GetWorkSpace();
  55.  
  56. my $justnow = time();
  57.  
  58. for ( my $query = 0 ; $query <= $#QUERIES ; $query++ ) {
  59.     my @CASES     = ();
  60.     my $queryDef  = $workspace->GetQueryDef( $QUERIES[$query][1] );
  61.     my $resultSet = $sqlSession->BuildResultSet($queryDef);
  62.  
  63.     $resultSet->Execute();
  64.     while ( $resultSet->MoveNext() == $CQPerlExt::CQ_SUCCESS ) {
  65.         push @CASES, [ $resultSet->GetColumnValue(2), $resultSet->GetColumnValue(7), $resultSet->GetColumnValue(8) ];
  66.     }
  67.  
  68.     foreach my $case (@CASES) {
  69.         my ( $caseId, $counter, $changeTime ) = @$case;
  70.  
  71.         # The counter is displayed in decimal days. Convert it to seconds by multiply by seconds per day
  72.         $counter *= $one_day;
  73.  
  74.         print "Case $caseId: Last changed $changeTime, $QUERIES[$query][0]=$counter\n";
  75.  
  76.         # Update the due counters and the due-date field
  77.         my $diff = $justnow - $changeTime;
  78.         print "Diff=$diff\n";
  79.         while ( $diff > 0 ) {
  80.             my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime($changeTime);
  81.             my $datestr = sprintf( "%4.4d-%2.2d-%2.2d", 1900 + $year, 1 + $mon, $mday );
  82.             if ( !$HOLIDAYS{$datestr} && $wday != 0 && $wday != 6 ) {
  83.  
  84.                 if   ( $diff > 3600 ) { $counter += 3600; }
  85.                 else                  { $counter += $diff; }
  86.             }
  87.  
  88.             if   ( $diff > 3600 ) { $changeTime += 3600; }
  89.             else                  { $changeTime += $diff; }
  90.             $diff -= 3600;
  91.         }
  92.  
  93.         my $objtoedit = $sqlSession->GetEntity( "Case", $caseId );
  94.  
  95.         $sqlSession->EditEntity( $objtoedit, "modify" );
  96.  
  97.         # Convert counter back to decimal days by divide by seconds per day
  98.         $counter /= $one_day;
  99.  
  100.         # For some very stupuid reason that I cannot understand, the variable values to be used to update
  101.         # the field value must be referenced here, otherwise we will get an error message TODO: WHY?
  102.         #        $a = "$counter\n";
  103.  
  104.         print "objtoedit->SetFieldValue( $QUERIES[$query][0], $counter )\n";
  105.         $objtoedit->SetFieldValue( $QUERIES[$query][0], $counter );
  106.  
  107.         # Wait until the last query to update the last_due_calc field, since it is retreived by all queries
  108.         if ( $query == $#QUERIES ) {
  109.             my $a = "$justnow\n";
  110.             $objtoedit->SetFieldValue( 'Last_Due_Calc_time', $justnow );
  111.         }
  112.  
  113.         # Validate the changes. (Must be done in order to be able to commit the changes)
  114.         if ( $objtoedit->Validate() eq "" ) {
  115.             $objtoedit->Commit();
  116.         }
  117.         else {
  118.             $objtoedit->Revert();
  119.             print "Failed $caseId $QUERIES[$query][0]=$counter, calctime=$justnow\n";
  120.         }
  121.     }
  122.  
  123. }
  124.  
Histrory part
------------------

Expand|Select|Wrap|Line Numbers
  1. Date/Time    User Name    Action:    Old State    New State  
  2.  2008-02-19 14:19:33     edtalte     submit     no_value     Submitted   
  3.  2008-02-19 16:36:13     sqluser     modify     Submitted     Submitted   
  4.  2008-02-19 16:36:14     sqluser     modify     Submitted     Submitted   
  5.  2008-02-19 16:36:35     sqluser     modify     Submitted     Submitted   
  6.  2008-02-19 16:36:36     sqluser     modify     Submitted     Submitted   
  7.  2008-02-19 16:39:56     sqluser     modify     Submitted     Submitted   
  8.  2008-02-19 16:39:57     sqluser     modify     Submitted     Submitted   
  9.  2008-02-19 16:43:59     sqluser     modify     Submitted     Submitted   
  10.  2008-02-19 16:44:00     sqluser     modify     Submitted     Submitted   
  11.  2008-02-19 16:53:03     sqluser     modify     Submitted     Submitted   
  12.  2008-02-19 16:53:03     sqluser     modify     Submitted     Submitted   
  13.  2008-02-19 16:53:11     sqluser     modify     Submitted     Submitted   
  14.  2008-02-19 16:53:11     sqluser     modify     Submitted     Submitted   
  15.  2008-02-19 16:55:21     sqluser     modify     Submitted     Submitted   
  16.  2008-02-19 16:55:22     sqluser     modify     Submitted     Submitted   
  17.  2008-02-19 17:00:01     sqluser     modify     Submitted     Submitted   
  18.  2008-02-19 17:00:02     sqluser     modify     Submitted     Submitted   
  19.  2008-02-20 08:00:03     sqluser     modify     Submitted     Submitted   
  20.  2008-02-20 08:00:04     sqluser     modify     Submitted     Submitted   
  21.  2008-02-20 09:00:05     sqluser     modify     Submitted     Submitted   
  22.  2008-02-20 09:00:06     sqluser     modify     Submitted     Submitted   
  23.  2008-02-20 10:00:02     sqluser     modify     Submitted     Submitted   
  24.  2008-02-20 10:00:03     sqluser     modify     Submitted     Submitted   
  25.  2008-02-20 12:00:02     sqluser     modify     Submitted     Submitted   
  26.  2008-02-20 12:00:04     sqluser     modify     Submitted     Submitted   
  27.  2008-02-20 13:00:26     sqluser     modify     Submitted     Submitted   
  28.  2008-02-20 13:00:28     sqluser     modify     Submitted     Submitted   
  29.  2008-02-21 08:00:11     sqluser     modify     Submitted     Submitted   
  30.  2008-02-21 08:00:13     sqluser     modify     Submitted     Submitted   
  31.  2008-02-21 09:00:02     sqluser     modify     Submitted     Submitted   
  32.  2008-02-21 09:00:03     sqluser     modify     Submitted     Submitted   
  33.  2008-02-21 10:00:02     sqluser     modify     Submitted     Submitted   
  34.  2008-02-21 10:00:03     sqluser     modify     Submitted     Submitted   
  35.  2008-02-21 12:00:02     sqluser     modify     Submitted     Submitted   
  36.  2008-02-21 12:00:03     sqluser     modify     Submitted     Submitted   
  37.  2008-02-21 13:00:02     sqluser     modify     Submitted     Submitted   
  38.  2008-02-21 13:00:02     sqluser     modify     Submitted     Submitted   
  39.  2008-02-21 14:00:03     sqluser     modify     Submitted     Submitted   
  40.  2008-02-21 14:00:04     sqluser     modify     Submitted     Submitted   
  41.  2008-02-21 14:17:01     sqluser     modify     Submitted     Submitted   
  42.  2008-02-21 14:17:02     sqluser     modify     Submitted     Submitted   
  43.  2008-02-21 15:00:05     sqluser     modify     Submitted     Submitted   
  44.  2008-02-21 15:00:11     sqluser     modify     Submitted     Submitted
Feb 22 '08 #4

Kelicula
Expert 100+
P: 176
I am sorry but, I still don't understand what you mean by "updating history part".

Do you have "default" values set up in the Database for those fields?

If a field is set to "not null", and you update some other field within the same record, the "default" value will be used to update the fields that were left blank.

I am not experienced with "CQPerlExt". For database transactions I use the DBI module.

You may want to move @CASES out of the loop, since declaring it with "my" within a loop will create warnings, when "strict" pragma is used.
(line 59)

I recommend using "strict" in all your scripts.
Feb 22 '08 #5

KevinADC
Expert 2.5K+
P: 4,059
This is going to be a tooth pulling session so I am out of the thread.
Feb 22 '08 #6

eWish
Expert 100+
P: 971
The easiest approach would be to delete the code that does the updating of the history that you don't want to keep anymore.

We do not know which section of code is doing the updating. Comment out each of the areas one at a time until it does what you want.

Make sure your scripts use the strict and warnings pragmas to assist in your debugging efforts.

That is all we can tell you since your description and lack of information is not helping us help you.

--Kevin
Feb 23 '08 #7

P: 5
What the system is:
I have a defect tracking system. In that I have defects that are said to be CASES. And I have all information about that defects i.e., CaseId, title, description, Attachment and History also. It contains when the case is opened, closed and timestamp etc.

What the requirement is:
What the requirement is I have to implement a field which says that the cases has to be closed in these many days. By that users can know the elapsed time to solve the case.

What I have done:
Basically it is a counter which calculates elapsed time in seconds and after that it is converted to days. Here we are considered holidays and national holidays as well.
And I updated the counter field by using modify action. Then this action modifies all the fields of history also.
When ever I call that script that action updates history also, and then there will be so many entries in that history. And I need to call the script an hour basis. So per day there are 24 entries that will be big problem

What I need:
I donít want to update case history. Is there any possibility to update the only one filed?







I am sorry but, I still don't understand what you mean by "updating history part".

Do you have "default" values set up in the Database for those fields?

If a field is set to "not null", and you update some other field within the same record, the "default" value will be used to update the fields that were left blank.

I am not experienced with "CQPerlExt". For database transactions I use the DBI module.

You may want to move @CASES out of the loop, since declaring it with "my" within a loop will create warnings, when "strict" pragma is used.
(line 59)

I recommend using "strict" in all your scripts.
Feb 25 '08 #8

eWish
Expert 100+
P: 971
Is this homewor/classwork?
Feb 25 '08 #9

P: 5
Already this system is using by a major client in Europe. I need to implement new requirements.

Is this homewor/classwork?
Feb 25 '08 #10

eWish
Expert 100+
P: 971
Okay, I have a better understanding now. What is the exact name of the field in the database for "Cases", the field you don't want to update?

In the code you posted I do not see where you are writing any data to the database. Where are the queries located that do the writing?

Would you please post some of the queries?

--Kevin
Feb 26 '08 #11

KevinADC
Expert 2.5K+
P: 4,059
Okay, I have a better understanding now. What is the exact name of the field in the database for "Cases", the field you don't want to update?

In the code you posted I do not see where you are writing any data to the database. Where are the queries located that do the writing?

Would you please post some of the queries?

--Kevin

He should really be asking on a forum that discusses ClearQuest

http://www.ibm.com/developerworks/fo...pa?forumID=329

Here is almost the exact same question posted on the CLearQuest forum:

http://www.ibm.com/developerworks/fo...94537&tstart=0
Feb 26 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.