{"id":28027,"date":"2017-06-16T15:07:30","date_gmt":"2017-06-16T07:07:30","guid":{"rendered":"http:\/\/localhost\/help\/?page_id=28027"},"modified":"2024-07-08T06:37:09","modified_gmt":"2024-07-07T22:37:09","slug":"current","status":"publish","type":"page","link":"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/current\/","title":{"rendered":"Current()"},"content":{"rendered":"\n<h2>Format<\/h2>\n<p class=\"intro-text\"><strong>Current([Suffix] [,CallingDataObjectType])<\/strong><\/p>\n<h2>Returns<\/h2>\n<p class=\"intro-text\">Returns the name of the current data object or fetches it by appending a suffix to it, depending on the parameters.<\/p>\n<h2>Inputs<\/h2>\n<p class=\"intro-text\"><b>Suffix: <\/b>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.<br \/>\nBehaviour: Optional<br \/>\nDimensions: SingleValue<br \/>\nValid data types: Null, String<\/p>\n<p class=\"intro-text\"><b>CallingDataObjectType: <\/b>The type of the current data object to filter by in the call stack. Valid values are: CalculationDataset, CalculationTag, and Entity (default).\u00a0If this parameter is omitted, the function will return an entity name (see note at end of the Call Stack Example).<br \/>\nBehaviour: Optional<br \/>\nDimensions: SingleValue<br \/>\nValid data types: String<\/p>\n<p class=\"left-bar\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/calculation-syntax\/#Data_Type\">How to format data types<\/a><\/p>\n<h2>How it Works<\/h2>\n<p class=\"intro-text\">The Current(), <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/initial\/\">Initial<\/a>(), and <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/caller\/\">Caller<\/a>() functions work by using an internal call stack to fetch the name of an entity.\u00a0These functions operate in a similar way to the <em>Entity<\/em> <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/keywords\/\">keyword<\/a>, and are useful for creating <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/glossary\/templated-calculation\/\">templated calculations<\/a>.<\/p>\n<p class=\"intro-text\">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.\u00a0<\/p>\n<p class=\"intro-text\">The call stack lives only during the evaluation of an expression, and every expression which is being evaluated (i.e. every request sent to IFS OI Server) has its own call stack. Each item in the call stack has an associated <em>type<\/em>, which shows what was added. The type can be a calculation dataset, calculation tag, or entity.<\/p>\n<p class=\"intro-text\"><strong>Call Stack Example<\/strong><\/p>\n<p class=\"intro-text\">During the evaluation of an expression, IFS OI Server creates an internal call stack and the Current() function allows you to access information from this call stack.\u00a0<\/p>\n<p class=\"intro-text\">If you have the following configuration with Archer, Ballard, and Cattle entities, then during the evaluation of <em>{Archer:Choke}<\/em>, the call stack will look like this:<\/p>\n<table>\n<tbody>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\"><strong>Expression<\/strong><\/td>\n<td><strong>Call stack (with type)<\/strong><\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\">{Archer:Choke}<\/td>\n<td>Archer - entity<\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\">{Ballard:Choke}<\/td>\n<td>Ballard - entity<br \/>\nArcher - entity<\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\">{Cattle:Choke}<\/td>\n<td>Cattle - entity<br \/>\nBallard - entity<br \/>\nArcher - entity<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"intro-text\">Now let's create a calculation tag called <strong>{Calculation}<\/strong> and point {Cattle:Choke} to this tag, so that {Calculation}={Cattle:Choke}.\u00a0In this scenario, <em>Archer<\/em> calls <em>Ballard<\/em>, which calls <em>Cattle<\/em>, which calls <em>Calculation<\/em>.<\/p>\n<p class=\"intro-text\">When {Calculation} is evaluated, the call stack will be:<\/p>\n<ol start=\"0\">\n<li class=\"intro-text\">Calculation <em>(this is the name of the expression being evaluated)\u00a0<\/em>\u2013 calculation tag<\/li>\n<li class=\"intro-text\">Cattle \u2013 entity<\/li>\n<li class=\"intro-text\">Ballard \u2013 entity<\/li>\n<li class=\"intro-text\">Archer \u2013 entity<\/li>\n<\/ol>\n<p class=\"intro-text\">Now, let's assign different expressions to\u00a0{Calculation} so we can see what the outcomes would be, given the above call stack:<\/p>\n<table>\n<tbody>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\"><strong>Calculation<\/strong><\/td>\n<td><strong>Result<\/strong><\/td>\n<td><strong>Notes<\/strong><\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\"><span style=\"color: #0000ff;\">{Calculation} = Current()<\/span><\/td>\n<td><span style=\"color: #0000ff;\">Cattle<\/span><\/td>\n<td><span style=\"color: #0000ff;\">The CallingDataObjectType parameter defaults to filter the stack by <em>entity.<\/em><\/span><\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\"><span style=\"color: #0000ff;\">{Calculation} =\u00a0Current(\"\", \"CalculationTag\")<\/span><\/td>\n<td><span style=\"color: #0000ff;\">Calculation<\/span><\/td>\n<td><span style=\"color: #0000ff;\">The CallingDataObjectType parameter filters the stack by <em>calculation tag<\/em>.\u00a0<\/span><\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\">{Calculation} = Caller(0)<\/td>\n<td>Cattle<\/td>\n<td>This is similar to <em>Current()<\/em>.<\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\">{Calculation} = Caller(-1)<\/td>\n<td>Ballard<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\">{Calculation} = Caller(-2)<\/td>\n<td>Archer<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\">{Calculation} = Caller(-3)<\/td>\n<td><em>Error<\/em><\/td>\n<td>Returns an error since the call stack is not that deep<\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td style=\"padding-left: 5px;\">{Calculation} = Initial()<\/td>\n<td>Archer<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"note\">Note: By default, functions that use the call stack search for <strong>entity<\/strong> names. If you want the <em>calculation<\/em> name when using Current() or Caller(0), then you should pass \"CalculationTag\" as the last parameter i.e. <em>Current(null, \"CalculationTag\").<\/em> <em><br \/>\n<\/em>So, the call stack can vary what Current() is pointing to, depending on what the function is passing for the <em>CallingDataObjectType<\/em>. I.e. If it\u2019s looking for entities, then Current() will look for the first <em>entity<\/em> type on the call stack, not necessarily the first thing on the call stack.<\/p>\n<h2>Using the Calculation Tester<\/h2>\n<p class=\"intro-text\">The <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/configuring-your-system\/creating-a-calculation\/using-the-calculation-tester\/\">Calculation Tester<\/a>\u00a0is unable to process expressions using the <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/caller\/\">Caller<\/a>(), <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/initial\/\">Initial<\/a>(), and Current() functions, because the required entity call stack is not exposed by the <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/configuring-your-system\/creating-a-calculation\/using-the-calculation-editor\/\">Calculation Editor<\/a>.<\/p>\n<p class=\"intro-text\">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.<\/p>\n<h2>Examples<\/h2>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Current()<\/span><br \/>\nResult: Returns the name of the current entity which is being processed.<\/p>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Current(\"[Oil Producing Well]:Choke\")<\/span><br \/>\nResult: Appends \"[Oil Producing Well]:Choke\" to the name of the current entity and evaluates the generated expression.<\/p>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Current(null, \"CalculationTag\")<\/span><br \/>\nResult: Returns the name of the current calculation tag.<\/p>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Current(\"Value\", \"CalculationTag\")<\/span><br \/>\nResult: Appends \"Value\" to the name of the current calculation tag and evaluates the generated expression.<\/p>\n<p class=\"intro-text\">Expression:\u00a0<span class=\"code-fragment\">Current(\":Choke\") * 1.4<\/span><br \/>\nResult:\u00a0Will multiply the value of the Choke attribute attached to the current entity by 1.4.<\/p>\n<p class=\"intro-text\">Expression:\u00a0<span class=\"code-fragment\">Current(\":Choke!Current Position\") * 1.4<\/span><br \/>\nResult:\u00a0Will multiply the Current Position attribute value of the Choke attribute attached to the current entity by 1.4.<\/p>\n<p class=\"intro-text\">Expression:\u00a0<span class=\"code-fragment\">DDGet(\"IFS Corporate\", 1, Current(), \":Choke!Current Position\", \"\", \"Oil Producing Well\")<\/span><br \/>\nResult: Will return the value of the current choke position attached to the current entity, for Oil Producing Wells in the IFS Corporate hierarchy.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Returns the name of the current data object or fetches it by appending a suffix to it, depending on the parameters.<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/current\/\">Read more<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":28065,"parent":3650,"menu_order":75,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[9],"tags":[100],"class_list":["post-28027","page","type-page","status-publish","has-post-thumbnail","hentry","category-tech-ref","tag-calculations","Version-4-5-1","Product-srv"],"_links":{"self":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/28027","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/comments?post=28027"}],"version-history":[{"count":3,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/28027\/revisions"}],"predecessor-version":[{"id":67889,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/28027\/revisions\/67889"}],"up":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/3650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media\/28065"}],"wp:attachment":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media?parent=28027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/categories?post=28027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/tags?post=28027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}