How to validate data on the dialog box ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 06:56 AM
There is a requirement when problem record changes from root cause analysis to fix in progress, Cause notes and fix notes should be mandatory.But those fields has predifined text already, because of that without entering any new values on those fields,it is allowing to submit.
I need to validate if it has already predifined text and end user doesn't enter any values,It should throw error message to the user to fill those fields.
How can i achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2023 08:43 AM
Hi @janani sundaram ,
For UI action "Fix" the UI Script "ProblemModalUIHelpers" is called in UI action. So you need to update the code of UI Script "ProblemModalUIHelpers".
Update the code like below.
ProblemModalUIHelpers.onFix = function() {
var view = g_form.getViewName();
if (!g_form.hasField("state")) {
getMessage('Cannot proceed to fix the Problem as \'State\' is not visible', function(msg) {
g_form.addErrorMessage(msg);
});
return false;
}
g_form.setValue("state", g_scratchpad.STATE.FIX_IN_PROGRESS);
var cnotes=g_form.getValue('cause_notes'); // this part you need to add
cnotes.split('test');
var newText=cnotes[5];
var fnotes=g_form.getValue('fix_notes'); // this part you need to add
fnotes.split('test');
var Text=fnotes[5];
if (g_form.mandatoryCheck() && newText!='' && Text!='') {
g_form.save();
return;
}
g_form.clearMessages();
var sysId = g_form.getUniqueValue();
var ob = new ProblemModalUIHelpers();
var formValues = {
state: g_scratchpad.STATE.FIX_IN_PROGRESS
};
ob.openModal('start_fix_dialog_form_view', getMessage('Fix'), 850, formValues, "move_to_fix_in_progress");
};
If my answer resolves your issue then please mark it as correct and helpful.
Regards,
Devender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2023 09:21 AM
Hi @janani sundaram ,
Hope you are doing great.
To achieve the required validation for the fields "Cause notes" and "Fix notes" in the ServiceNow problem record, we can implement a client-side script.
function onSubmit() {
var causeNotes = g_form.getValue('cause_notes');
var fixNotes = g_form.getValue('fix_notes');
var predefinedText = "Enter your cause notes here...";
var errorMessage = "Please provide both Cause notes and Fix notes.";
// Check if both fields have the predefined text and no new values are entered
if (causeNotes === predefinedText && fixNotes === predefinedText) {
g_form.addErrorMessage(errorMessage);
return false; // Prevent the form from being submitted
}
return true; // Allow the form to be submitted if validation passes
}
Regards,
Riya Verma