CQ

脚本1: Add a Validation field hook  modify the user_number field for the Defect record type.  user_number is a Mandatory field during Submit.  write a Validation field hook to ensure the length of the user_number is exactly six characters long. 『Basic: Dim session Dim user_number Set session = GetSession Session.OutputDebugString "user_number_Validation for " & fieldname & vbCrLf set user_number = GetFieldValue (fieldname) FieldValue = user_number.GetValue() If (Len(FieldValue)<>6) then session.OutputDebugString "strlen is " & Len(fieldValue) & vbCrLf user_number_Validation = "Invalid entry. Must be 6 characters." exit function End if Perl: $session->OutputDebugString("user_number_Validation for $fieldname/n"); my $user_number = $entity->GetFieldStringValue($fieldname); my $fieldlen = length($user_number); if ($fieldlen != 6) { $session->OutputDebugString("strlen is length $fieldlen/n"); $result = "Invalid entry. Must be 6 characters."; }』脚本2: Create dependent fields  create two new fields: Platform and OS.  write a Choice List field hook such that the choice_list for OS depends upon the value of Platform. 『Basic: Dim platform platform = GetFieldValue("Platform").GetValue() select case platform case "WINDOWS" choices.AddItem ("Win98") choices.AddItem ("WinNT") choices.AddItem ("Win2K") choices.AddItem ("WinXP") case "UNIX" choices.AddItem ("Solaris") choices.AddItem ("Linux") choices.AddItem ("AIX") end select Perl: my $platform = $entity->GetFieldStringValue("Platform"); if ($platform eq "WINDOWS") { push(@choices, "Win98", "WinNT", "Win2K", "WinXP"); } elsif ($platform eq "UNIX") { push(@choices, "Solaris", "Linux", "AIX"); } else { push(@choices, " "); }』脚本3: Build a field to have consecutive Ids  add a new field called Last_ID of INT type to the Project stateless record type.  add a Consecutive_ID field for the Defect record type.  write a Validation action hook in the Submit action for the Defect record type to get the consecutive id value 『Basic: Dim IDEntity Dim MySession Dim IDCounterObject Set MySession = GetSession Set IDEntity = MySession.GetEntity("Project","MyProj") Set IDCounterObject = IDEntity.GetFieldValue("LastID") MySession.EditEntity IDEntity,"Modify" IDEntity.SetFieldValue "LastID", IDCounterObject.GetValue() + 1 IDEntity.Validate IDEntity.Commit SetFieldValue "Consecutive_ID", IDCounterObject.GetValue() + 1 Perl: my $IDEntity = $session->GetEntity("Project", "MyProj"); my $IDvalue = $IDEntity->GetFieldStringValue("LastID"); $IDvalue += 1; $IDEntity->EditEntity("Modify"); $IDEntity->SetFieldValue("LastID", "$IDvalue"); $IDEntity->Validate(); $IDEntity->Commit(); $entity->SetFieldValue("Consecutive_ID", "$IDvalue");』脚本4: Add a record script  add a new field, KeyCustomer, to the Defect record type.  write a record script to set the value of KeyCustomer based upon the selected control. 『Basic: Dim eventType eventType = param.EventType If eventType = AD_BUTTON_CLICK Then SetFieldValue "KeyCustomer", "Button Company" Elseif eventType = AD_CONTEXMENU_ITEM_SELECTION Then SetFieldValue "KeyCustomer", "Menu Inc." End if Perl: my $eventType = $param->EventType(); if ($eventType == $CQPerlExt::CQ_BUTTON_CLICK) { $entity->SetFieldValue("KeyCustomer", "Button Company"); } elsif ($eventType == $CQPerlExt::CQ_CONTEXMENU_ITEM_SELECTION) { $entity->SetFieldValue("KeyCustomer", "Menu Inc."); }』脚本5: Write a global script, add a BASE action, write a record script, and add a RECORD_SCRIPT_ALIAS action  write a global script to check if a user database MYUSR is available.  add a BASE action, Update, to indicate the action status.  write a record script to execute the written global script.  add a RECORD_SCRIPT_ALIAS action, Confirm, to run the new record script for confirming the status. 『Basic:全局函数 Function Check_Database() dim adminSession dim dbList dim dbObj set adminSession = CreateObject("ClearQuest.AdminSession") adminSession.Logon "admin", "", "CQAdmin" set dbList = adminSession.Databases numDBs = dbList.Count - 1 for x = 0 to numDBs set dbObj = dbList.Item(x) dbName = dbObj.Name if dbName = "MYUSR" then Check_Database = TRUE exit Function else Check_Database = FALSE end if next End Function 功能1 dim old_state dim curr_state old_state = GetFieldOriginalValue("state").GetValue() curr_state = GetFieldValue("state").GetValue() if curr_state <> old_state then SetFieldValue "status", "Transition" else SetFieldValue "status", "In-state" end if 功能2 Dim session Dim this_entity Set session = GetSession username = session.GetUserLoginName displayName = GetDisplayName Set this_entity = session.GetEntity("Defect", displayName) session.EditEntity this_entity, "Modify" If Check_Database() and username = "admin" then SetFieldValue "status", "Confirmed" Else SetFieldValue "status", "Unconfirmed" End if this_entity.Validate this_entity.Commit Perl: 全局函数 sub Check_Database { my $dbObj; my $adminSession = CQAdminSession::Build(); $adminSession->Logon("admin", "", "CQAdmin"); my $dbList = $adminSession->GetDatabases(); my $numDBs = $dbList->Count(); my $result = FALSE; for ($x=0;$x<$numDBs;$x++) { $dbObj = $dbList->Item($x); if ($dbObj->GetName() eq "MYUSR") { $result = TRUE; last; } } CQAdminSession::Unbuild($adminSession); return $result; } 功能1 my $old_state = $entity->GetFieldOriginalValue("state")->GetValue(); my $curr_state = $entity->GetFieldValue("state")->GetValue(); if ($curr_state ne $old_state) { $entity->SetFieldValue("status", "Transition"); } else { $entity->SetFieldValue("status", "In-state"); } 功能2 $entity->EditEntity("Modify"); my $username = $session->GetUserLoginName(); if (&Check_Database && ($username eq "admin")) { $entity->SetFieldValue("status", "Confirmed"); } else { $entity->SetFieldValue("status", "Unconfirmed"); } $entity->Validate(); $entity->Commit();』脚本6 use the ClearQuest API functions to Submit a defect 『Perl: #!perl -w use CQPerlExt; #get the ClearQuest session my $session = CQSession::Build() or die "$!"; $session->UserLogon("admin", "", "SAMPL", "CQAdmin"); #create the new entity object my $newDefect = $session->BuildEntity("Defect"); #Setting up the content of the new entity $newDefect->SetFieldValue("Headline", "Using API functions to submit defects does work"); $newDefect->SetFieldValue("Severity", "1-Critical"); $newDefect->SetFieldValue("Priority", "1-Resolve Immediately"); $newDefect->SetFieldValue("Owner", "admin"); $newDefect->SetFieldValue("Description", "We can use external programs to submit defects."); $newDefect->Validate(); $newDefect->Commit(); CQSession::Unbuild($session);』脚本7 use the ClearQuest API functions to List all defect records in a ClearQuest user Database,to Modify a record 『Perl: #!perl -w use CQPerlExt; # Start by obtaining a CQSession object and logging in to the SAMPL database # -------------------------------------------------------------------------- my $session = CQSession::Build() or die "$!"; $session->UserLogon("admin", "", "SAMPL", "CQAdmin"); # Build & Execute a Query to find all Defect records, retrieving the # "id", "Headline", and "State" fields in the Query result set # ------------------------------------------------------------------ my $querydef = $session->BuildQuery("Defect"); $querydef->BuildField("id"); $querydef->BuildField("Headline"); $querydef->BuildField("State"); my $resultset = $session->BuildResultSet($querydef); $resultset->Execute(); print "DEFECT ID STATE HEADLINE/n"; # Loop through the result set, printing the field values for each Defect # ---------------------------------------------------------------------- while ($resultset->MoveNext() == 1) { $id = $resultset->GetColumnValue(1); $head = $resultset->GetColumnValue(2); $state= $resultset->GetColumnValue(3); printf("%-15s %-10s %s/n",$id, $state, $head); } # Modify the Headline field of the Defect record whose ID is "SAMPL00000012" # -------------------------------------------------------------------------- my $rec = $session->GetEntity("Defect", "SAMPL00000012"); $rec->EditEntity("Modify"); $rec->SetFieldValue("Headline", "THIS DEFECT HAS BEEN MODIFIED!"); $rec->Validate(); $rec->Commit(); # Clean up the CQSession to release the CQ license and DB Connection # ------------------------------------------------------------------ CQSession::Unbuild($session);』
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值