For some forms you may want the default values of fields to be dependant on user-specific criteria. In the most likely scenario, these default values are determined by data from an external database (likely linked to an SSO integration and involving external API calls), and require a changing the initial data that is loaded into the form.
However there is not a specific event we can hook into to trigger this function, so instead we use the fact that window.InitFormData is only loaded into the form once, and we set it to the result of a function using the following script:
window.InitFormData = function(formdata) {
//Some function you have created to modify the initial formdata - eg:
ChangeLoadedData(formdata);
//You must then return the modified formdata object to set this in the window
return formdata;
}
The system will run the window.InitFormData function into the form after you have loaded any data from a Syntaq record. This means that to avoid overwriting any data the user might have manually overwritten when they saved or submitted the form to create the new record, it is important that your function which modifies the loaded data (ChangeLoadedData(formdata), for example) has checks in place to only change data if the field is currently undefined. For example:
function ChangeLoadedData(formdata) {
OtherFunction(); //some function used to get data from external source
//for this example it creates a data object called otherdata
if (formdata.Field_Name_txt === undefined) {
formdata.Field_Name_txt = otherdata.UserName;
}
}
As the window.InitFormData function is only run once, you can also use it as an event trigger of sorts to set system fields or do other functions on form load.
Comments
0 comments
Article is closed for comments.