A hook cannot determine whether a field is READONLY for the user by calling the GetFieldRequiredness API. From a hook context, any field can be modified, so the GetFieldRequiredness API will never return READONLY to a hook. The GetFieldRequirednessForUser API always returns the user’s view of the field behavior, whether it is called from a hook context or not.
Perl
$entity->GetFieldRequirednessForUser(field_name);
Perl
# Change all MANDATORY fields to OPTIONAL
# Retrieve the collection of fields
$fieldnamelist = $entity->GetFieldNames();
foreach $fieldname (@$fieldnamelist)
{
# Find out if the selected field is mandatory
$fieldreq = $entity->GetFieldRequirednessForUser($fieldname);
if ($fieldreq eq $CQPerlExt::CQ_MANDATORY)
{
# Since it is, make it optional
$entity->SetFieldRequirednessForCurrentAction($fieldname,
$CQPerlExt::CQ_OPTIONAL);
}
}
For more information, refer to http://www-01.ibm.com/support/docview.wss?uid=swg21129438