Current()

Format

Current([Suffix] [,CallingDataObjectType])

Returns

Returns the name of the current data object or fetches it by appending a suffix to it, depending on the parameters.

Inputs

Suffix: If this parameter is null (default) then the name of the current data object will be returned. If this parameter is a string, it will be appended to the name of the current data object and it will be evaluated/fetched.
Behaviour: Optional
Dimensions: SingleValue
Valid data types: Null, String

CallingDataObjectType: The type of the current data object to filter by in the call stack. Valid values are: CalculationDataset, CalculationTag, and Entity (default). If this parameter is omitted, the function will return an entity name (see note at end of the Call Stack Example).
Behaviour: Optional
Dimensions: SingleValue
Valid data types: String

How to format data types

How it Works

The Current(), Initial(), and Caller() functions work by using an internal call stack to fetch the name of an entity. These functions operate in a similar way to the Entity keyword, and are useful for creating templated calculations.

Whenever an attribute value is evaluated, the name of the entity is added to an internal stack and these functions allow you to access these names from the stack. It is important to note that these functions operate based on this internal call stack, and not on hierarchies. 

The call stack lives only during the evaluation of an expression, and every expression which is being evaluated (i.e. every request sent to P2 Server) has its own call stack. Each item in the call stack has an associated type, which shows what was added. The type can be a calculation dataset, calculation tag, or entity.

Call Stack Example

During the evaluation of an expression, P2 Server creates an internal call stack and the Current() function allows you to access information from this call stack. 

If you have the following configuration with Archer, Ballard, and Cattle entities, then during the evaluation of {Archer:Choke}, the call stack will look like this:

Expression Call stack (with type)
{Archer:Choke} Archer - entity
{Ballard:Choke} Ballard - entity
Archer - entity
{Cattle:Choke} Cattle - entity
Ballard - entity
Archer - entity

Now let's create a calculation tag called {Calculation} and point {Cattle:Choke} to this tag, so that {Calculation}={Cattle:Choke}. In this scenario, Archer calls Ballard, which calls Cattle, which calls Calculation.

When {Calculation} is evaluated, the call stack will be:

  1. Calculation (this is the name of the expression being evaluated) – calculation tag
  2. Cattle – entity
  3. Ballard – entity
  4. Archer – entity

Now, let's assign different expressions to {Calculation} so we can see what the outcomes would be, given the above call stack:

Calculation Result Notes
{Calculation} = Current() Cattle The CallingDataObjectType parameter defaults to filter the stack by entity.
{Calculation} = Current("", "CalculationTag") Calculation The CallingDataObjectType parameter filters the stack by calculation tag
{Calculation} = Caller(0) Cattle This is similar to Current().
{Calculation} = Caller(-1) Ballard  
{Calculation} = Caller(-2) Archer  
{Calculation} = Caller(-3) Error Returns an error since the call stack is not that deep
{Calculation} = Initial() Archer  

Note: By default, functions that use the call stack search for entity names. If you want the calculation name when using Current() or Caller(0), then you should pass "CalculationTag" as the last parameter i.e. Current(null, "CalculationTag").
So, the call stack can vary what Current() is pointing to, depending on what the function is passing for the CallingDataObjectType. I.e. If it’s looking for entities, then Current() will look for the first entity type on the call stack, not necessarily the first thing on the call stack.

Using the Calculation Tester

The Calculation Tester is unable to process expressions using the Caller(), Initial(), and Current() functions, because the required entity call stack is not exposed by the Calculation Editor.

These types of expressions would work only if they are evaluated through attribute values. For testing purposes, we recommend replacing these calls with the desired entity names in the Calculation Editor.

Examples

Expression: Current()
Result: Returns the name of the current entity which is being processed.

Expression: Current("[Oil Producing Well]:Choke")
Result: Appends "[Oil Producing Well]:Choke" to the name of the current entity and evaluates the generated expression.

Expression: Current(null, "CalculationTag")
Result: Returns the name of the current calculation tag.

Expression: Current("Value", "CalculationTag")
Result: Appends "Value" to the name of the current calculation tag and evaluates the generated expression.

Expression: Current(":Choke") * 1.4
Result: Will multiply the value of the Choke attribute attached to the current entity by 1.4.

Expression: Current(":Choke!Current Position") * 1.4
Result: Will multiply the Current Position attribute value of the Choke attribute attached to the current entity by 1.4.

Expression: DDGet("P2 Corporate", 1, Current(), ":Choke!Current Position", "", "Oil Producing Well")
Result: Will return the value of the current choke position attached to the current entity, for Oil Producing Wells in the P2 Corporate hierarchy.

 

Comments are closed