RAD function: policyread

A RAD function that reads the data policy from a datadict table.

Function

policyread

Format

$L.returnvalue = policyread( $L.file/$filename, fieldname, fieldsetting)

Parameters

The following parameters are valid for this function.

Parameter

Description

$L.returnvalue

The policy value returned after it is read from the database. It can be a string, a boolean, or null.

$L.file/$filename

This can be either a file variable or a file name:

$L.file - The file handle of the table for which the data policy information is to be read from the database. It can be a join table, a normal table or an adhoc table.

Note: Other kinds of tables (merge files, etc.) are not supported.

$filename – The name of the table for which the data policy information is to be read from the database. It can be a normal table only.

Note: All other kinds of tables are not supported.

The table name is the value in the Name field in the datadict record.

fieldname

The name of the field in the specified table for which the data policy information is to be read from the database.

The field name is the value in the Field Name field in the datadict record.

fieldsetting

The field setting on the specified field for which the data policy information is to be read from the database.

If no field setting is passed in when calling policyread function, the function will return true if the field exists in data policy, otherwise will return false.

This is one of the fields on Field Settings tab of the datadict record.

Valid field settings are: "invisible", "readonly", "mandatory", "captions", "avail","encrypt", "defaults", "globallist", "matchfields", "matchfiles", and "validations", ”types”, “reference.table”.

In addition, there two special settings: “display.field”, “autocomplete.show.field”, if one of these settings is specified, the field name will be ignored.

Factors

If the fieldsetting is not in the list of Field Settings in the datadict table, the server will throw an error message. In any other case, this function returns a valid value or null.

Return values

A String, Boolean or null value.

Examples

Example 1

This example demonstrates how you could use a JavaScript to access the data policy on a simple file, such as the operator table.

// Access DataPolicy definition on operator file.

var operatorFile = new SCFile( "operator" );
var rteReturn;


rteReturn = system.functions.policyread( operatorFile , "profile.change", "invisible" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:invisible) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "readonly" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:readonly) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "mandatory" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:mandatory) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "captions" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:captions) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "avail" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:avail) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "encrypt" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:encrypt) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "defaults" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:defaults) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "globallist" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:globallist) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "matchfields" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:matchfields) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "matchfiles" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:matchfiles) " + rteReturn );

rteReturn = system.functions.policyread( operatorFile , "profile.change", "validations" );
print( "DataPolicy on (file:operator, fieldname:profile.change), as defined in (file:datadict, field:validations) " + rteReturn );
				

Example 2

This example demonstrates how you could use a JavaScript to access the data policy on a complex file, such as a join of the incidents and contacts tables.

// Access DataPolicy definitions on join file inccontacts (incidents and contacts)

var incident_contacts_file = new SCFile( "inccontacts" );
var rteReturn;

// Access policy definition on file(contacts) and field(city) and datadict field defaults
rteReturn = system.functions.policyread( incident_contacts_file, "file.contacts,city", "defaults" );
print( "DataPolicy on (joinfile:inccontacts, subfile:contacts, field:city), as defined in(file:datadict, field:defaults)" + rteReturn );

// Access policy definition on file(incidents) and field(phone) and datadict field defaults
rteReturn = system.functions.policyread( incident_contacts_file, "file.incidents,phone", "defaults" );
print( "DataPolicy on (joinfile:inccontacts, subfile:incidents, field:phone), as defined in(file:datadict, field:defaults)" + rteReturn );

// Access policy definition on file(incidents) and field(phone), and datadata field readonly
rteReturn = system.functions.policyread( incident_contacts_file, "file.incidents,phone", "readonly" );
print( "DataPolicy on (joinfile:inccontacts, subfile:incidents, field:phone), as defined in(file:datadict, field:readonly)" + rteReturn );
			

Example 3

function testPolicy()
{
	var file = new SCFile( 'cm3r' );
	
	var ret = system.functions.policyread(file, "assets", "reference.table" );
	print( "The reference.table attribute for assets field in cm3r file is: ", ret );
	
	ret = system.functions.policyread(file, "assets", "" );
	print( "assets field in cm3r exists in data policy: ", ret );

	ret = system.functions.policyread(file, "nofield", "" );
	print( "nofield field in cm3r exists in data policy: ", ret );
	
	ret = system.functions.policyread(file, "", "display.field" );
	print( "display.field for file cm3r is: ", ret );
	
	ret = system.functions.policyread("device", "", "display.field" );
	print( "display.field for file device is: ", ret );
}

Example 3 returns the following results:

The reference.table attribute for assets field in cm3r file is:  device
assets field in cm3r exists in data policy:  true
nofield field in cm3r exists in data policy:  false
display.field for file cm3r is:  null
display.field for file device is:  display.name