SetFieldRequirednessForCurrentAction

Description

Sets the behavior of a field for the duration of the current action.

Use this method to set the field behavior to mandatory, optional, or read-only. After the action has been committed, the behavior of the field reverts to read-only. You must have HCL Compass Administrator privileges to call this method from an external script. Also, you can call this method only if the Entity object is editable. To make an existing Entity object editable, call the EditEntity method of the Session object.

Note: After a hook changes a field property or value, you might need to refresh any local variables that correspond to the changed field or any other field. Setting a field value can cause hooks to fire which might change the value or required settings of any field in the record. Hooks or scripts might need to refresh local variables to keep them current with the values in the record. Refresh local variables when current values are needed.

Because a Record_script_alias is not a true entity action, the behavior of this function is undefined when used in a Record_script_alias action.

For integrations between base HCL Compass and HCL Compass, you cannot associate a HCL Compass record with a HCL VersionVault checkin if the HCL Compass record includes required (or mandatory) fields that do not have values specified. Users that try to perform this operation receive an exception error. Users must first enter values for the mandatory fields of the HCL Compass record; or the schema can be changed to provide a hook to be run on the Modify action using the SetFieldRequirednessForCurrentAction method to change the requiredness of a field.

Syntax

VBScript


entity.SetFieldRequirednessForCurrentAction field_name, newValue 

Perl


$entity->SetFieldRequirednessForCurrentAction(field_name, newValue); 
Identifier
Description
entity
An Entity object representing a user data record. Inside a hook, if you omit this part of the syntax, the Entity object corresponding to the current data record is assumed (VBScript only).
field_name
A String that identifies a valid field name of entity.
newValue
A Long identifying the new behavior type of the field. This value corresponds to one of the constants of the Behavior enumerated type. (It is not legal to use the USE_HOOK constant.)
Return value
None.

Examples

VBScript

' Change all mandatory fields to optional 
' Retrieve the collection of fields
fieldNameList = GetFieldNames 
For Each fieldName in fieldNameList 
	' Find out if the selected field is mandatory 
	fieldReq = GetFieldRequiredness(fieldName) 
	if fieldReq = AD_MANDATORY 
	' Since it is, make it optional 
	Then SetFieldRequirednessForCurrentAction fieldName, AD_OPTIONAL 
	End If 
Next 

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->GetFieldRequiredness($fieldname);
   if ($fieldreq eq $CQPerlExt::CQ_MANDATORY)
   { 
   # Since it is, make it optional
   $entity->SetFieldRequirednessForCurrentAction($fieldname, $CQPerlExt::CQ_OPTIONAL);
   }
}