Accessing dates from related apps in calculation field

Comments

8 comments

  • Rainer Grabowski

    Hi Nicolas,

    if there is only one App B item related you can use

    @max of date

    or

    @min of date

    or

    moment(@all of date.toString()).toDate().

    What do you mean by "in the new date format"? 

    Rainer

    0
    Comment actions Permalink
  • Marcos Adlercreutz

    Hi to all!

    i have a situation...

    I have two related fields:

    App A: @Fecha Pre-Aprobación (value = 05/01/2017)

    App B: Related with App B

    I type on calculation field: moment(@All of Fecha Pre-Aprobación.toString()).toDate()

    It returns a different date 31/12/1969. 

     

    Any ideas?

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Marcos,

    some questions: 

    1. Is the calculation field in App B?
    2. Which field type is Fecha Pre-Aprobación - a text field of a "normal" date field?
    3. If calculation field in B: Is there only 1 A-item related or multiple?
    4. Is @All of Fecha Pre-Aprobación (in the moment() function) blue?

    Rainer

    0
    Comment actions Permalink
  • Marcos Adlercreutz

    Rainer,

    1. Is the calculation field in App B? => Yes, it is
    2. Which field type is Fecha Pre-Aprobación - a text field of a "normal" date field? => It´s a normal date field
    3. If calculation field in B: Is there only 1 A-item related or multiple? => It´s multiple. Actually, when i´m about to select the field it shows me the same field "incomming" and "outcomming". Could this be a problem?
    4. Is @All of Fecha Pre-Aprobación (in the moment() function) blue? => Yes, it is in blue

     

    Thanks in advance!

    0
    Comment actions Permalink
  • Rainer Grabowski

    ok, I see. 2 issues:
    1. Incoming and Outgoing are different, you have to select the right reference. Via Outgoing you get those A-items which you have added in the relationship field in the B-time. Incoming are those where this B-item is added in a relationship field in A.
    One tip: Try to avoid vice versa relationships, in my opinion in 99% of the cases it's unnecessary to have vice versa relations (for me it's bad app design).

    2. If there are multiple items related through the reference you've selected (outgoing/incoming) @all of Fecha Pre-Aprobación returns all related dates in one array, something like ["01/05/2017", "02/05/2017","03/052017"]. If you make it a string with .toString() the string looks like "01/05/2017, 02/05/2017,03/052017" - and for the function .moment() that's an invalid date and it returns 31/12/1969. If there is only one item related .moment( @all of Fecha Pre-Aprobación.toString()).toDate() should return the right result.  So you have to select one date from the array which should be shown in the calcualtion field, e.g 
    @all of Fecha Pre-Aprobación[0] is the oldest of the related item (= the one of the related items which has been createdf first)
    @all of Fecha Pre-Aprobación [ @all of Fecha Pre-Aprobación.length-1] is the newest created. 

    Rainer

    0
    Comment actions Permalink
  • Marcos Adlercreutz

    Rainer, think i´ve got it!

    The thing is that i had several relationships between two apps. The change i made is that i select @all of... with nulls outcoming.

    That made the difference... I don´t have knowledge about javascript or other languages so this is everything new.

    Is it a bad thing to do, to have incoming and outcomming relations between apps? I´m trying to understand to avoid future issues.

    Eg:

    Sometimes, make templates like this:

    App A: Contacts

    - Field Name

    - Related field with project (so i can select multiple projects at one time)

    App B: Project

    - Field Title

    - Related field with contacts (so i can select multiple contacts at one time)

    See my point?

     

    0
    Comment actions Permalink
  • Marcos Adlercreutz

    Rainer, you answered me before i asked! :)  Thanks!

    I´ve checked and, in this case, i don´t have related fields on both sides (vice versa).

    The thing is that some of the information or fields in app B are used in calculation fields of app A.

    Other thing, would i use @all of... with nulls? when do you sugest to use it?

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    @all of .. with nulls is only necessary if you want to match/concatenate/combine 2 or more fields from App A in a calculation in App B, e.g in a for-loop. If you only want to pull from one field (like in your example) it's not necessary. But if you use array ... with nulls in loops you have to get the elements with [i][0], not only [i]. The reason: ... with nulls returns the items in a nested array:
    [["01/05/2017"], [],["02/05/2017"],[],["03/052017"]] 

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk