My question is:

What kind of field would you use in an Appian interface to display [but not allow editing] of a field like "created by" and "created date" that you want to display but not allow user editing - such that the data from these fields is actually stored into the database.

Details of issue:

My colleague and I are fairly new to appian development and are working on a problem.

She created an interface that that allows us to add and edit the rows in a particular reference table.

The interfae [mostly] works - in that it allows you to add and edit rows in the database table.

The problem we have however is that there are some fields, which are not supposed to be directly edited by users. For example:

"Created by" "Created date"

Rather than the users adding values for these fields, we want them to be automatically set by the system by retrieving the currently logged in user and the system date.

My colleague has been able to set the field values to their initial states using the loggedInUser() function and the now() function.

        a!textField(
          label: "Created by",
          labelPosition: "ABOVE",
          value: if(ri!RefDataTable.referenceId, ri!RefDataTable.createdby , loggedInUser()),
          saveInto: a!save(ri!RefDataTable.createdby, upper(save!value)),
          characterLimit: 255,
        )

and

        a!localVariables(
          local!storedValue1:now(),
          a!dateTimeField(
            label: "Created Date and Time",
            value: if(ri!RefDataTable.referenceId, ri!RefDataTable.createddate, local!storedValue1),
            saveInto:{
              a!save(ri!RefDataTable.createddate, local!storedValue1)
            },
          )
        )

However, it seems that these values are not transferred into the database unless the lose-focus event is triggered for the field, which causes the method recorded against the "saveInto" field to be executed.

So it becomes necessary for the user to manually click on each of these fields and then out of them again for the values to get into the object that will then be stored into the database. If this is not done, then even though the form appears to save the record, it does not actually save any of the data at all.

I am thinking that perhaps some field type other than a!textField() should be used for the "created by" fields. Further, perhaps some field type other than a!dateTimeField() should be used for the "date created" fields - since we don't actually want the user to edit these - but rather we simply want to store the values extracted from the system into these fields.

However, to date, we have not been able to figure out how to capture the point at which the data is stored to the database so that we can [simply] store the values into the database [presumably via the CDT] at the point the record is stored.

1

There are 1 answers

0
mouse_s On BEST ANSWER

You should not write to the db from an interface it is very difficult to follow data if you do.

The recommended solution is to pass the values captured in the interface upon submission and pass it along to process variables and perform the db updates in another node in the process.

avoid a!writeToDataStoreEntity() if you are not experienced.

a!localVariables(
  local!currentUser: loggedInUser(),
  a!formLayout(
    contents: {
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!textField(
                label: "Customer",
                value: ri!customer,
                saveInto: ri!customer,
                readOnly: false
              ),
              a!textField(
                label: "User",
                value: local!currentUser,
                readOnly: true
              )
            }
          )
        }
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          submit: true,
          saveInto: {
            a!save(ri!currentUsser, local!currentUser)
          }
        )
      }
    )
  )
)

regarding the date issue you can display one date in the interface and insert another into the database just create an script task right before writing to the db and write that date instead. This is one technique among others.