AnsweredAssumed Answered

Calculation Context Behaving Mysteriously

Question asked by johnhorner on Apr 12, 2011
Latest reply on Apr 13, 2011 by johnhorner


Calculation Context Behaving Mysteriously


I have a table of CONTACTS, and a table of CONTACT RELATIONSHIPS which is used to display related contacts in a portal on a CONTACTS layout.  There are multiple relationships set up between CONTACTS and CONTACT RELATIONSHIPS.  For example, one portal shows "employees" of a given contact, while another displays non-employment related contacts (such as a friend or family member).  both of these portals use the same container field as a handle to add drag and drop sorting capability to the portal.  this container field has an auto enter calculation to help determine the appropriate sorting behavior.  I set this up first in the "employee" portal and it worked fine.  i then set it up in the "non-employment related" portal and, to my surprise, it also worked fine even though the calculation was set up to evaluate from the context of the "employee" relationship using the "current" (same) table.  here is the calculation:

     Let ( [
     _trigger = Handle_ContactRelationshipsSort ;
     $$DroppedIntoField = "Handle_ContactRelationshipsSort" ;
     $$DroppedInto_ID = __kp_ContactRelationship_ID ;
     $$CreationTimestamp = Timestamp_Creation ;
     $$DroppedIntoEmptyRow = If ( ( Get ( CurrentTimeStamp ) - Timestamp_Creation ) < 1 ; "Yes" ; "No" ) ;
     $$SortOrder_Down = Case (
          IsEmpty (contacts_CONTACT_RELATIONSHIPS_Employees_Sort_Lower::SortOrder_Related ) ; Ceiling ( SortOrder_Related ) -1 ;
          ( SortOrder_Related + contacts_CONTACT_RELATIONSHIPS_Employees_Sort_Lower::SortOrder_Related ) / 2
          ) ;
     $$SortOrder_Up = Case (
          IsEmpty ( contacts_CONTACT_RELATIONSHIPS_Employees_Sort_Higher::SortOrder_Related ) ; Int ( SortOrder_Related ) + 1 ;
          ( SortOrder_Related + contacts_CONTACT_RELATIONSHIPS_Employees_Sort_Higher::SortOrder_Related) / 2
     ] ;
     GRAPHIC_ELEMENTS::g_DragAndDrop [1]

My question is: How can this calculation possibly work correctly in the "non-employment related" portal when it is evaluating the sort field based on a different relationship and a different T.O.?  it works even if there are no empoyment related records so anything seeking to evaluate the field "contacts_CONTACT_RELATIONSHIPS_Employees_Sort_Higher::SortOrder_Related" should return empty... right?  How does the "Evaluate this calculation from the context of:" actually work?