- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2020 07:50 PM
Hi Guys,
I have a OnSubmit Client Scripts as below, tried to add in "g_form.clearMessages();" in order to clear the precious error messages, but it still leaving the first error on top and unable to clear it. (If I remove the "g_form.clearMessages();" , the error will keep stacking up when the user press the Submit button for second / third time etc.
Any suggestion on the ways to clear All the Error PopUp previously then only show the new Error Message (if any) ??
===================================================================
function onSubmit() {
if(g_form.getValue("Variable_1") == "Yes") {
g_form.clearMessages();
g_form.addErrorMessage("Not suitable for storing Government or Banking data.");
return false;
}
if(g_form.getValue("Variable_2") == "Yes") {
g_form.clearMessages();
g_form.addErrorMessage("Not suitable for storing Highly Confidential Data.");
return false;
}
if(g_form.getValue("Variable_3") == "Yes") {
g_form.clearMessages();
g_form.addErrorMessage("Not suitable for storing Personal Data (Beyond Business card details).");
return false;
}
}
=======================================================================
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-05-2020 04:50 PM
Hi Guys,
thanks for trying to help, I have solved this myself by using the OnChange function:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//When "will you be storing Government Data" selected with "No", it will clear the message
if (isLoading || newValue == 'No') {
g_form.clearMessages();
return;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2020 11:59 PM
Hi Anish,
Tried, the previous error pop up still "hanging" there on the screen. Is your side have any instance to try out the best scenario ??
1) user click the Submit button, it shows the Error Message
2) then the user corrected the Yes/No Selection, click the submit button again
3) need it to clear the previous message that showing up on the screen, then if having any new error, will have new error to shows up, what would be the best way to archive this ??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-31-2020 03:56 AM
Hi Jason,
Looks like its a bug / some weird issue that even I was able to reproduce the same error. I tried in this way. However, its a workaround, probably it will be useful for your current project and upcoming projects as well.
Create a Widget (Name = ValidationOnSubmit)
Body HTML Template
<script type="text/ng-template" id="validationfailure">
<div class="panel panel-default" style="text=align:justify;">
<div class="panel-heading">
<h4 class="panel-title"><strong>Validation Failed</strong></h4>
</div>
<div class="panel-body wrapper-xl" style="text=align:justify;padding-left:5px;">
<p ng-bind-html="c.errormessage"></p>
</div>
<div class="panel-footer text-center">
<button class="btn btn-primary" ng-click="c.closeModal()">${Ok}</button><br>
</div>
</div>
</script>
Client Controller
function validatecc($uibModal, $scope) {
var c = this;
c.errormessage = '';
c.closeModal = function() {
c.modalInstance1.close();
};
CustomEvent.observe('validateonsubmit', function() {
var msgtxt = "";
if ($scope.page.g_form.getValue("Variable_1").toString().indexOf("Yes") > -1) {
msgtxt = "<li>Variable 1: Not suitable for storing Government or Banking data.</li>";
}
if ($scope.page.g_form.getValue("Variable_2").toString().indexOf("Yes") > -1) {
if(msgtxt == ""){
msgtxt = "<li>Variable 2: Not suitable for storing Highly Confidential Data.</li>";
}else{
msgtxt += "<li>Variable 2: Not suitable for storing Highly Confidential Data.</li>";
}
}
if ($scope.page.g_form.getValue("Variable_3").toString().indexOf("Yes") > -1) {
if (msgtxt == '') {
msgtxt = "<li>Variable 3: Not suitable for storing Personal Data (Beyond Business card details).</li>";
} else {
msgtxt += "<li>Variable 3: Not suitable for storing Personal Data (Beyond Business card details).</li>";
}
}
if (msgtxt != '') {
c.errormessage = "<ul>" + msgtxt.toString() + "</ul>";
c.modalInstance1 = $uibModal.open({
templateUrl: 'validationfailure',
scope: $scope
});
return false;
} else {
c.errormessage = "";
$scope.page.g_form.submit();
}
});
}
--------------------------------------------------
- On your Catalog Item, create a Macro variable. You don't need to worry about adding this Macro as this doesn't change anything as far as your functionality is concerned.
- Open "OnSubmit" Client script that you currently have. Remove all the code and add the below code.
function onSubmit() {
try {
CustomEvent.fire('validateonsubmit');
return false;
} catch (e) {
}
}
Note: We can use this kind of Popup when we need to validate multiple variables together.
Thanks,
Narsing

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2020 11:39 PM
Hi
As per your code, you are clearing the error messages and then adding g_form.addErrorMessge. And in onsubmit you are checking for variables and adding messages. so check which message is being shown and see if that is added after clear or before?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2020 11:56 PM
Hi asifnoor,
Ya, the situation needed is like let say the user click the Submit button, it shows the Error Message, then the user corrected the Yes/No Selection, click the submit button again, need it to clear the previous message that showing up on the screen, then if having any new error, will have new error to shows up, what would be the best way to archive this ??
Thanks for trying to help guys!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-30-2020 01:31 AM
In that case, just add
g_form.clearMessages at the first line of onSubmit before all conditions. It will clear any errors that were there before.
Mark the comment as correct/helpful if it helps.