I have a form that allow the users to import a file (BLOB), put a comment and a date.
I had to create a validation function, to check if the fields are empty, here's why :
The default validation returns "undefined" when the file browser is empty, and the validation text is not translated when it is a date picker, even though i translated the message in my shared components :
- So, I decided to create a Dynamic Action with a JavaScript Expression to check the fields and display errors.
apex.message.clearErrors();
var chkErr = 0;
//declare fields
var arr = [
'P28_BLOB_DOCUMENT',
'P28_COMMENTAIRE_DOCUMENT',
'P28_DATE_DOCUMENT'
];
//declare Labels
var arrLabel = [
"Importer un document",
"Commentaire",
"Date d'exportation"
];
//Check NULL
for (var i in arr) {
if ($v(arr[i]).length == 0) {
apex.message.showErrors([
{
type: apex.message.TYPE.ERROR,
location: ["inline", "page"],
pageItem: arr[i],
message: arrLabel[i] " doit contenir une valeur",
unsafe: false
}
]);
chkErr = 1;
}
}
if ( chkErr == 0 ) {
/* Custom dynamic action call when no error occurred */
apex.message.confirm("Do you want to import this document ?", function(okPressed) {
if (okPressed) {
apex.submit({request:'insertDocumentProcess'});
//apex.submit('insertDocumentProcess');
}
});
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
Everythings works, if I add this DA to my button, I have my validations :
Now here comes the real problem, if I use the Dynamic Action on the CREATE
button, the auto process "Form - Automatic Row Processing (DML)", is not executing anymore. Even tough I tried to call it using the apex.submit('insertDocumentProcess');
or apex.submit({request:'insertDocumentProcess'});
, the INSERT
action is not executing on the database.
Here are all the details :
- The create button, with the code explained above
- The process that is generated automatically when creating the form, that I try to call
Did I miss something ? The INSERT
was working fine when I'm not adding the validation function, so is the problem related to the way I'm calling the process ? Or is it because I'm trying to INSERT a BLOB FILE and I'm missing something ?
I tried different options, with another DA calling the process, but It wasn't successful.
I still have the success message from the process at the end, saying "Row created", but it doesn't appear in the database. Could it still confirm that I'm calling successfully the process ?
Thanks in advance,
CodePudding user response:
Add a Client-side Condition
in your Dynamic Action checkErrors
. Pick JavaScript expression
to verify if text fields pass the validation or not
Example
(
apex.item('P28_BLOB_DOCUMENT').isEmpty() ||
apex.item('P28_COMMENTAIRE_DOCUMENT').isEmpty() ||
apex.item('P28_DATE_DOCUMENT').isEmpty()
)
True action
should be the JavaScript code that validates empty fields (code you posted above).
apex.message.clearErrors();
var chkErr = 0;
//declare fields
var arr = [
'P28_BLOB_DOCUMENT',
'P28_COMMENTAIRE_DOCUMENT',
'P28_DATE_DOCUMENT'
]; //this is the code you pasted above
False action
should be an Action: Submit Page
and fill the option Request / Button Name
: CREATE
to tell APEX that you want to Insert
or SAVE
if you want to Update
, this will reproduce the same behavior of normal submit.
Let me know if you have questions.