Calculation between records in a grid - Number of days between dates

Certified Senior Developer

Hi All,

I have grid displaying certain records for a specific user, lets say I want to calculate how many days did it take the user to create the next record so for example in the image attached the user created a few on the same day, so if I wanted to add another column next to this one to display number of days, how can I achieve this? the calculation part? because I need to grab the first date of the previous record with the date of the next created record and so on . 

Is this even possible, or what are your suggestions on finding this kind of information?

Thanks in advance

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    a!localVariables(
    local!records:{} /* Query records sorted by createdDate for a specific user */,

    local!recordWithDays: a!forEach(
    items: local!records,
    expression: a!map(
    recordId: fv!item.recordId,
    createdDate: fv!item.createdDate,
    userId: fv!item.userId,
    daysSinceLastRecord: if(
    fv!index = 1,
    null, /* No previous record for the first one */
    days360(
    date1: fv!item.createdDate,
    date2: local!records[fv!index - 1].createdDate,

    )&" days"
    )
    )
    ),

    a!gridField(
    label: "User Records",

    columns: {
    a!gridColumn(
    label: "Record ID",
    value: fv!row.recordId
    ),
    a!gridColumn(
    label: "Created Date",
    value: fv!row.createdDate
    ),
    a!gridColumn(
    label: "Days Since Last Record",
    value: fv!row.daysSinceLastRecord
    )
    },
    data: local!recordWithDays
    )
    )

Reply
  • 0
    Certified Lead Developer

    a!localVariables(
    local!records:{} /* Query records sorted by createdDate for a specific user */,

    local!recordWithDays: a!forEach(
    items: local!records,
    expression: a!map(
    recordId: fv!item.recordId,
    createdDate: fv!item.createdDate,
    userId: fv!item.userId,
    daysSinceLastRecord: if(
    fv!index = 1,
    null, /* No previous record for the first one */
    days360(
    date1: fv!item.createdDate,
    date2: local!records[fv!index - 1].createdDate,

    )&" days"
    )
    )
    ),

    a!gridField(
    label: "User Records",

    columns: {
    a!gridColumn(
    label: "Record ID",
    value: fv!row.recordId
    ),
    a!gridColumn(
    label: "Created Date",
    value: fv!row.createdDate
    ),
    a!gridColumn(
    label: "Days Since Last Record",
    value: fv!row.daysSinceLastRecord
    )
    },
    data: local!recordWithDays
    )
    )

Children
No Data