{"id":28028,"date":"2017-06-16T15:07:18","date_gmt":"2017-06-16T07:07:18","guid":{"rendered":"http:\/\/localhost\/help\/?page_id=28028"},"modified":"2024-07-04T16:12:46","modified_gmt":"2024-07-04T08:12:46","slug":"initial","status":"publish","type":"page","link":"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/initial\/","title":{"rendered":"Initial()"},"content":{"rendered":"\n<h2>Format<\/h2>\n<p class=\"intro-text\"><strong>Initial([Suffix] [,CallingDataObjectType])<\/strong><\/p>\n<h2>Returns<\/h2>\n<p class=\"intro-text\">Returns the name of the initial calling 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 initial calling data object will be returned. If this parameter is a string, it will be appended to the name of the calling 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 calling 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<h2>How it Works<\/h2>\n<p class=\"intro-text\">The\u00a0Initial(), <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/current\/\">Current<\/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\">The Initial() function is different to the Caller() and Current() functions, in that it operates from the other end of the call stack.\u00a0Initial() always gets the very first entry from the call stack, that is, the one that started the calculation chain. This function is useful when you don't know how deep the call stack would be.<\/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 <em>(this is the top of the call stack, and the starting point for Initial())<\/em><\/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;\">{Calculation} = Current()<\/td>\n<td>Cattle<\/td>\n<td>The CallingDataObjectType parameter defaults to filter the stack by <em>entity.<\/em><\/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>The CallingDataObjectType parameter defaults to filter the stack by <em>entity.<\/em><\/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>The CallingDataObjectType parameter defaults to filter the stack by <em>entity.<\/em>\u00a0<\/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;\"><span style=\"color: #0000ff;\">{Calculation} = Initial()<\/span><\/td>\n<td><span style=\"color: #0000ff;\">Archer<\/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} =\u00a0Initial(null, \"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><\/span><\/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 Initial(), then you should pass \"CalculationTag\" as the last parameter i.e. <em>Initial(null, \"CalculationTag\")<\/em>.<em><br \/>\n<\/em>So, the call stack can vary what Initial() is pointing to, depending on what the function is passing for the <em>CallingDataObjectType<\/em>. I.e. If it\u2019s looking for entities, then Initial() 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 Initial(),\u00a0<a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/caller\/\">Caller<\/a>(), and <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/current\/\">Current<\/a>() 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\">Initial()<\/span><br \/>\nResult: Returns the name of the entity that triggered the evaluation.<\/p>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Initial(\"[Oil Producing Well]:Choke\")<\/span><br \/>\nResult: Appends \"[Oil Producing Well]:Choke\" to the name of the first entity it finds on the call stack, and evaluates the generated expression.<\/p>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Initial(null, \"CalculationTag\")<\/span><br \/>\nResult: Returns the name of the first calculation tag it finds from the call stack.<\/p>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Initial(\"Value\", \"CalculationTag\")<\/span><br \/>\nResult: Appends \"Value\" to the name of the first calculation tag it finds on the call stack, and evaluates the generated expression.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Returns the name of the initial calling 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\/initial\/\">Read more<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":28078,"parent":3650,"menu_order":124,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[9],"tags":[100],"class_list":["post-28028","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\/28028","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=28028"}],"version-history":[{"count":2,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/28028\/revisions"}],"predecessor-version":[{"id":67798,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/28028\/revisions\/67798"}],"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\/28078"}],"wp:attachment":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media?parent=28028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/categories?post=28028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/tags?post=28028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}