The EditEntity method performs the specified action on a record and makes the record available for editing. The Entity object you specify in the entity parameter must have been previously obtained by calling GetEntityByDbId or GetEntity, or by running a query.
$session->EditEntity(entity, edit_action_name);
You can get the list of legal values for the edit_action_name parameter, call the GetActionDefNames method of the appropriate EntityDef object.
# Build Session object... # Edit the record whose ID is "BUGDB00000010" using the "modify" action $objtoedit = $sessionobj->GetEntity("defect", "BUGDB00000010"); $sessionobj->EditEntity($objtoedit,"modify");
After calling the EditEntity method, you can call the methods of the Entity object to modify the fields of the corresponding record. You can also get additional information about the type of data in the fields or about the record as a whole, or change the behavior of a field for the duration of the current action.
The SetFieldValue method places the specified value in the named field. If the field can be changed, this method sets its new value, regardless of whether that value is valid, and returns the empty String.
To determine whether a field contains a valid value, obtain the FieldInfo object for that field and call the ValidityChangedThisSetValue method of the FieldInfo object to validate the field. If the field cannot be changed, the returned String indicates why the field cannot be changed. Typical values include "no such field", "record is not being edited", and "field is read-only". If the field can have multiple values instead of just one, use the AddFieldValue method to add each new value. It is still legal to use SetFieldValue; however, using SetFieldValue on a field that already contains a list of values replaces the entire list with the single new value. You can call this method only if the Entity object is editable.
$entity->SetFieldValue(field_name, new_value);
To edit an existing record, follow these steps:
use CQPerlExt; #Getting the session my $session = CQSession::Build(); CQSession::UserLogon ($session, "admin", "", "SAMPL", "Lab3"); my $querydef = $session->BuildQuery ("defect"); $querydef->BuildField ("id"); $querydef->BuildField ("headline"); my $resultset = $session->BuildResultSet ($querydef); $resultset->Execute(); while (($resultset->MoveNext()) == 1) { $id = $resultset->GetColumnValue(1); $rec = $session->GetEntity("Defect", $id); $head = $rec->GetFieldValue("Headline")->GetValue(); $state= $rec->GetFieldValue("State")->GetValue(); print "$id, $head, $state. \n"; if ($id eq "SAMPL00000012") { $session->EditEntity($rec, "Modify"); $rec->SetFieldValue("description", "This defect has been modified."); $status = $rec->Validate(); if ( $status ){ $rec->Revert; die "Validation Error: $status \n" } else { # Only commit the changes if the validation is first successful. $rec->Commit(); } } } CQSession::Unbuild($session);