Skip to main content
kavyam0002
January 25, 2022
Question

Auto Populate

  • January 25, 2022
  • 5 replies
  • 0 views

Hi,

I have two date fields last-updated and next-update,

when i enter last-updated date then next-update field need to be auto populated (last-upadate+2years= next-update)

how can i achieve this?

Thanks,

Kavya 

    5 replies

    stewart.burchell
    January 25, 2022

    When your user selects a value for the 'last-updated' date you can add, on that same date field component, an a!save() to save the derived value of last-upadate+2years into the variable that you are using as the value attribute of your 'next-update' field. Assuming you don't want your user to override the 'next-update' value you should make this read-only and use a different component to display its value (i.e. the underlying variable type will be date but a read-only display of this value should be a text field, where you can use the text() function to render a friendly date, like "Tuesday 25th March 2022")

    stewart.burchell
    January 25, 2022

    Here's an example of what I meant:

    a!localVariables(
      local!lastUpdated: null,
      local!nextUpdate: null,
      {
        a!dateField(
          label: "Last UHpdated",
          value: local!lastUpdated,
          saveInto: {
            local!lastUpdated,
            a!save(
              local!nextUpdate,
              local!lastUpdated + (365 * 2)
            )
          }
        ),
        a!textField(
          label: "Next Update",
          readOnly: true,
          value: if(
            fn!isnull(local!nextUpdate),
            "",
            fn!text(local!nextUpdate, "ddd mmm yyyy")
          )
        )
      }
    )

    gopalk2865
    Participating Frequently
    January 25, 2022

    Hi Kavya,

    In the first date field's save into , save the calculated value for second date field. something like below,

    a!datefield(

    label:"last_updated",

    value: local!last_pdated,

    saveInto{

    local!last_updated,

    a!save(local!next_update,edate(local!last_pdated, 24))

    }

    )

    harshitb6843
    January 25, 2022

    Hi Gopal,

    You can use it. 

    gopalk2865
    Participating Frequently
    January 25, 2022

    Thanks Harshit