Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1177309
  • 博文数量: 312
  • 博客积分: 12522
  • 博客等级: 上将
  • 技术积分: 3376
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-27 18:35
文章分类

全部博文(312)

文章存档

2016年(3)

2015年(1)

2013年(1)

2012年(28)

2011年(101)

2010年(72)

2009年(13)

2008年(93)

分类: 项目管理

2008-03-24 13:02:06

脚本1: Add a Validation field hook

n        modify the user_number field for the Defect record type.

n        user_number is a Mandatory field during Submit.

n        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

n        create two new fields: Platform and OS.

n        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

n        add a new field called Last_ID of INT type to the Project stateless record type.

n               add a Consecutive_ID field for the Defect record type.

n        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

n        add a new field, KeyCustomer, to the Defect record type.

n               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

n        write a global script to check if a user database MYUSR is available.

n        add a BASE action, Update, to indicate the action status.

n        write a record script to execute the written global script.

n        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

Databaseto 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);

阅读(1062) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~