Change onSubmit Client Script to onChange
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 02:30 AM
Hi All,
I have got a working onSubmit Script for the Demand table, essentially when a few specified fields are left with a zero value and the Demand is submitted a pop up appears, sort of like a warning to make you aware.
I now need this to also trigger when the Demand moves into the "Qualified" State, I have tried a few things but am not able to get it working and I assumed that the easiest option would be to use a separate onChange script but as mentioned before had no luck with it, below is the onSubmit script currently in use:
function onSubmit() {
function mandatoryFieldValueLabels() {
var labels = '';
var fieldNames = ['financial_benefit','capital_outlay','operational_outlay','u_external_cost'];
var emptyFields = fieldNames.filter(function(field) {
return g_form.getIntValue(field) <= 0;
});
var fieldLabels = emptyFields.map(function(fieldName) {
g_form.hideFieldMsg(fieldName);
g_form.showFieldMsg(fieldName, 'Check valid zero value', 'error');
return g_form.getLabelOf(fieldName);
});
return fieldLabels.join('\n').trim();
}
if (g_form.getActionName() == 'sysverb_insert') { // Was 'qualify' changed with STRY0018402
var zeroFieldValues = mandatoryFieldValueLabels();
if (zeroFieldValues.length > 0) {
var result = confirm('The following finance fields have a zero value, please confirm you wish to proceed: \n\n' + mandatoryFieldValueLabels());
if (!result) {
return false;
}
}
}
}
Any help would be greatly appreciated.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 02:01 AM
Hi @patrykprejs ,
First thing please deactivate onSubmit Client script.
then update the onChange Client script as below-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Check if the state has changed to "Qualified"
if (g_form.getValue('state') === 'Qualified') {
var zeroFieldValues = mandatoryFieldValueLabels();
if (zeroFieldValues.length > 0) {
var result = confirm('The following finance fields have a zero value. Do you wish to proceed?\n\n' + zeroFieldValues);
if (!result) {
g_form.setValue('state', oldValue); // Roll back the state change
}
}
}
}
function mandatoryFieldValueLabels() {
var labels = '';
var fieldNames = ['financial_benefit', 'capital_outlay', 'operational_outlay', 'u_external_cost'];
var emptyFields = fieldNames.filter(function(field) {
return g_form.getIntValue(field) <= 0;
});
var fieldLabels = emptyFields.map(function(fieldName) {
g_form.hideFieldMsg(fieldName);
g_form.showFieldMsg(fieldName, 'Check valid zero value', 'error');
return g_form.getLabelOf(fieldName);
});
return fieldLabels.join('\n').trim();
}
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 02:55 AM
Hi @Community Alums,
I have deactivated the onSubmit Script and used the script above but unfortunately it still just goes to qualified without giving me the little pop up warning.
Thanks,
Patryk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 09:44 AM
Hi @patrykprejs ,
I think there is some issue with the script.
Can you try the script again, this has the logs.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
console.log('State changed to: ' + newValue);
// Check if the state has changed to "Qualified"
if (newValue === 'Qualified') { // Replace 'Qualified' with the actual internal value if necessary
console.log('State is now Qualified');
var zeroFieldValues = mandatoryFieldValueLabels();
if (zeroFieldValues.length > 0) {
var result = confirm('The following finance fields have a zero value. Do you wish to proceed?\n\n' + zeroFieldValues);
if (!result) {
g_form.setValue('state', oldValue); // Roll back the state change
console.log('State change rolled back');
}
}
}
}
function mandatoryFieldValueLabels() {
var labels = '';
var fieldNames = ['financial_benefit', 'capital_outlay', 'operational_outlay', 'u_external_cost'];
var emptyFields = fieldNames.filter(function(field) {
return g_form.getIntValue(field) <= 0;
});
var fieldLabels = emptyFields.map(function(fieldName) {
g_form.hideFieldMsg(fieldName);
g_form.showFieldMsg(fieldName, 'Check valid zero value', 'error');
return g_form.getLabelOf(fieldName);
});
return fieldLabels.join('\n').trim();
}
Please ensure the field names are proper double check it.
and check the logs.
Thanks,
Sanjay Kumar