PilotScript Property List Functions

The following property list functions are available for PilotScript components.

The Property List functions operate on the overall data record property list and manipulate properties based on their name (text strings), not their value.

Property List Function Name/Prototype Description Example

IthProperty

Property IthProperty(Number index)
Returns a reference to a property with the given position number, which is arbitrary and carries no guarantees (useful for looping over all properties).
FOR #i in 1 .. NumProperties()

LOOP

   IthProperty(#i) += 5;

END LOOP;

Adds 5 to the value of every property.

IthPropertyName

String IthPropertyName(Number index)
Returns the name of the ith property on the current data record.
Resize(@List, 0);

FOR #i in 1 .. NumProperties() 
 LOOP

 APPEND(@List, IthPropertyName (#i));
END LOOP;

Creates a global array @List containing the names of all properties on the data record.

Keep

None Keep(String varname[, ...])
Takes one or more data record property names. Removes all but the specified properties from the data record property list.
Keep('Name', 'AlogP', 'Molecular_Weight'); 

Removes all properties from the data record property list, except for Name, AlogP, and Molecular_Weight.

Keep(Name[1], Name[2]); 

Keeps the properties where names are the values of Name[1] and Name[2].

Keep(@Array);

Keeps the properties whose names are stored as elements in the global array property, @Array. A side effect of the Keep function is that the remaining properties are reordered as they are listed as arguments to the function.

MetaDataProperties

StringArrayValue MetaDataProperties(Property or String propName)
Returns an array of all the metadata properties that exist on the given property. If none, a zero-length array is returned.
MetaNames := MetaDataProperties('Weight');

Puts the array of metadata property names that exists on 'Weight' into 'MetaNames'.

MetaDataProperty

Property MetaDataProperty(Property or String propName, String metaPropName)
Accesses a metadata property on a property. Since it returns a property, you can inspect it, assign into it, or use IS DEFINED to check for existence.
IF (MetaDataProperty(Price, 'currency') IS NOT DEFINED)
 THEN
 MetaDataProperty(Price, 'currency') := ‘USD’;

END IF;

Tests whether the metadata property 'currency' exists on the property 'Price'. If not, the metadata property is created and assigned the value 'USD'.

NumProperties

Number NumProperties()

Returns the number of properties on the current data record; useful for looping over all properties. Do not add, rename, or remove properties while looping.

Resize(@List, 0);
FOR #i in 1 .. NumProperties() 
LOOP

   APPEND(@List, IthPropertyName (#i));

END LOOP;

Creates a global array @List containing the names of all properties on the data record.

Property

Property Property(String name)
Returns a reference to the property with the given name. You can assign to the reference or access its value.
@name := 'a';

Property('a') := 10;

Property(@name) += 10;

b := Property(@name);

Assigns the value 10 to the property A. Increments the property A by 10. Assigns the value of property A to property B. Properties B and A are each assigned a value of 20.

Remove

None Remove(String varname[, ...])
Takes any combination of one or more data record names.
Remove('a', 'b');

Removes the properties A and B from the data record property list.

RemoveAll

None RemoveAll()
Removes all properties from the data record property list.
RemoveAll();

Removes all properties from the data record property list.

RemoveMetaData

None RemoveMetaData(Property or String propName, String metaPropName)
Removes the given metadata property if it exists.
RemoveMetaData('Weight', 'Units');

Removes the metadata 'Units' from the property 'Weight'.

Rename

None Rename(String varnameold, String varnamenew)
Changes the name on the property list of varnameold to varnamenew.
A := 'This value is assigned to B';

Rename('A', 'B');

The property A is no longer on the property list. It is renamed to B with a value of "This value is assigned to B".

Reorder

None Reorder (String varname1, String varname2[, ...])
Changes the internal order of values on the property list, so they are in the given order, and moves them to the front of the property list. If a given property is not on the property list, it is added. Additional properties that may be on the property list have an undefined ordering.
Reorder('C', 'B', 'My Prop');

Reorders the properties in the data record property list to begin with "C" and "B" and "My Prop". The remaining properties in the property list have an undefined order, and follow "C", "B", and "My Prop". To reorder without creating any new properties, use Keep.

RKeep

None RKeep(String regexp)
Removes from the data record all properties whose names do not match the given regular expression.
RKeep('^activity');

Keeps only those properties with names that start with "activity". The caret (^) is the regular expression character for matching the start.

RKeep('base$');

Keeps only those properties that end with "base". The dollar sign ($) matches the end.

RKeep('^(activity|score)');

Keeps those properties that start (^) with "activity" or "score".

RPropertyNames

StringArray RPropertyNames (String regex)
Returns an array of strings with the names of all the properties on the current data item that match the supplied regular expression.
@props := RPropertyNames ('^A.*'); 

FOR @i in 1 .. numvalues(@props) 

LOOP 
   Rename(@props[@i], @props[@i] . '_new');
 
END LOOP; 

To rename all of the properties in the @props array, loop through the array and address each element of the array. Loops over all properties which start with "A" (the regular expression ^A.*) and renames them to end with "_new".

RRemove

None RRemove(String regexp)
Removes from the data record all properties with names matching the given regular expression.
RRemove('^activity');

Removes all properties with names that start with "activity". The caret (^) is the regular expression character for matching the start.

RRemove('base$');

Removes all properties that end with "base". The dollar sign ($) matches the end.

RRemove('^(activity|score)');

Removes all properties that start (^) with either "activity" or "score".

SearchAll

Boolean SearchAll (String regexpr)
Searches all values on the property list for a match to the supplied regular expression. It returns True if a property value is found that matches; otherwise it returns False.
IF searchall('steroid')
 THEN
   issteroid := 'true';

ELSE
   issteroid := 'false';

END IF;