Use Case: A form as 10 fields out of which 4 are auto filled when a user lands on the page (auto filled fields are: 1. create date , 2. modified date, 3.created by and 4.modified by), rest 6 fields requires users input. When user saves the form by clicking on save button the system is giving the message as it is saved. However, it doesn't save the data to the DB.
While manual debugging when the user modifies the auto-filled fields and then clicks on save button then all the data in 10 fields are saving to DB. I am not sure what is missing.
I followed this tutorial to create this form -https://docs.appian.com/suite/help/21.3/Records_Tutorial.html
For autofill of 4 fields I have used following functions:
1. create date: local!storedValue:now()
2. modified date: local!storedValue:now()
3.created by: loggedInUser()
4.modified by: loggedInUser()
Can someone help in fixing this issue? Thanks!
Discussion posts and replies are publicly visible
Are you saving the data from the local variables to the CDT fields using a!save function? Because before you submit the form you need to save it in the CDT fields.
A fields value is stored to a rule input ONLY on user interaction. I typically set default values using a few a!save() in the submit button.
i am trying with a!save(), but the appian doc. for a!save() says :Use a!save for each item that you want to modify or alter in a saveInto parameter. But I basically want to save the value from the field into database as it is displayed. without any modifications and without user interaction
saveInto
is there any way for that ?
yes i did save in the CDT field.
my code is:
a!localVariables(
local!storedValue:now(),
a!dateTimeField(
label: "Created Date and Time",
value: if(ri!ED__DT_iwmsReferences.referenceId, ri!ED__DT_iwmsReferences.createddate, local!storedValue),
saveInto: ri!ED__DT_iwmsReferences.createddate
)
),
Hi Madhu, you can save these fields' values in saveInto parameter of your "Save" button. So whenever user clicks on save button you would be passing pre populated values into your rule inputs. In the code you shared , your value is in a local variable called "local!storedvalue". Now you will have to pass this local variable value to your rule input, so your saveInto parameter of the save button should be something like below,
saveInto:{
a!save(ri!ED__DT_iwmsReferences.createddate,local!storedValue)
}
You have an IF condition in the "value" parameter. I suppose it works fine for the first condition but doesn't save the data for the second condition. So in that case, check out this code snippet:
a!localVariables( a!formLayout( contents: { local!storedValue: now(), a!dateTimeField( label: "Created Date and Time", value: if(ri!ED__DT_iwmsReferences.referenceId, ri!ED__DT_iwmsReferences.createddate, local!storedValue), saveInto: ri!ED__DT_iwmsReferences.createddate ), }, buttons: a!buttonLayout( primaryButtons: a!buttonWidget( label: "Submit", value: true, saveInto: { if( ri!ED__DT_iwmsReferences.referenceId, {}, a!save(ri!ED__DT_iwmsReferences.createddate, local!storedValue) ) } ) ) ) ),
So you mean there is no way the (correct value which is being displayed in the respective fields) values will be saved to the database without user interaction ?
You will probably need to change your way of solving a given problem. In Appian a field can display the underlying data stored in memory as a rule input or a local variable. As the user interacts with the interface, you can change this data. The important "trick" here is, that you cannot only change the data displayed in that field, but any other as well.
Now about storing data to DB. A database is considered an external system Appian has an integration to. So, to store data to the DB, your user submits the form and the process continues to a node which writes some data to DB. This data can be modified in the process using a script task.
I hope this gives you a few hints ...
My code is getting correct value, but saving only when user interacts with the field, i want something which lets the data save without user interaction to the field.
There are 2 ways to do so:
Try to disable your fields that do not require user interaction. There is a parameter known as "Disable" for almost all fields. You can uncheck it.
Or try to make your fields "readOnly". It will just display the value and the user wont be able to make changes to those fields. To do so, make your "readOnly" parameter = true()