Skip to main content
Known Participant
February 24, 2021
Solved

How to store the value in rule input if value and saveInto are not having same values.

  • February 24, 2021
  • 7 replies
  • 0 views

I want to store the value of 'Monitoring Day' text field into rule input. Please find the below code I am using:

a!textField(
label: "Monitoring Day",
labelPosition: "ABOVE",
value: text(ri!monitoringDate,"dddd"),
saveInto: a!save(ri!monitoringDetails.monitoringDay,save!value),
showWhen: not(isnull(ri!monitoringDate)),
required: false,
readOnly: true,
validations: {}
),

It is not storing value in ri!MonitoringDay.

    Best answer by csteward

    To add to Mike's notes, a typical solution for updating a value which is not interacted with on the form is by utilizing the saveInto parameter of your Submit button - or another button that is sure to have user interaction (necessary for updating values).

    /* Submit Button*/
    saveInto:{
      a!save(
        ri!monitoringDetails.monitoringDay,
        if(
          fn!isnull(ri!monitoringDate),
          null,
          text(ri!monitoringDate,"dddd")
        )
      )
    }

    7 replies

    mikes0011
    Brainy
    February 24, 2021

    2 things:

    1. for a simple SaveInto, you don't need to use a!save() unless you're trying to save a value different from the value parameter of the component.  In other words, here you could just type "saveInto: ri!monitoringDetails.monitoringDay"
    2. I see you have "readOnly" set to a value of true.  This means no user interaction will be possible on this text field, meaning that nothing in the saveInto parameter will ever execute.  Can you tell us a bit more about the use case that you would be trying to use this for?
    The Expression Guru
    ayushimAuthor
    Known Participant
    February 25, 2021

    As per the use case , If I enter the monitoringDate it should automatically display and save day corresponding to that date in rule input as read only field:

    mikes0011
    Brainy
    February 25, 2021

    If the user input is happening in the Monitoring Date field, then the saveInto will need to happen there.  This is where we end up needing a!save, it makes our job very easy:

    a!dateTimeField(
      label: "Monitoring Date",
      labelPosition: "ABOVE",
      value: ri!monitoringDate,
      saveInto: {
        ri!monitoringDate,
        a!save(
          ri!monitoringDetails.monitoringDay,
          text(save!value, "dddd"),
        )
      },
      required: true,
      readOnly: false,
      validations: {}
    ),
    
    a!textField(
      label: "Monitoring Day",
      labelPosition: "ABOVE",
      value: ri!monitoringDetails.monitoringDay,
      showWhen: not(isnull(ri!monitoringDate)),
      required: false,
      readOnly: true
    ),

    The Expression Guru
    csteward
    cstewardAnswer
    Brainy
    February 24, 2021

    To add to Mike's notes, a typical solution for updating a value which is not interacted with on the form is by utilizing the saveInto parameter of your Submit button - or another button that is sure to have user interaction (necessary for updating values).

    /* Submit Button*/
    saveInto:{
      a!save(
        ri!monitoringDetails.monitoringDay,
        if(
          fn!isnull(ri!monitoringDate),
          null,
          text(ri!monitoringDate,"dddd")
        )
      )
    }

    ayushimAuthor
    Known Participant
    February 25, 2021

    Thank you Chris.

    I have implemented the code suggested by you and it is working as per expectation.