- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 12:24 AM - edited 08-04-2023 12:51 AM
Dear Team,
Please help here.
Currently, the below onChange Client Script (script include called) is functioning fine, but NOT displaying an error field message just below the Variable (date_to_disable_account)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var disDate = new GlideAjax('validateDisableDate');
disDate.addParam('sysparm_name', 'nowDateTime');
disDate.addParam('sysparm_disable_date', g_form.getValue('date_to_disable_account'));
disDate.getXML(compareDisableDate);
function compareDisableDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer < 0) { //To allow current date but not past date
//g_form.addErrorMessage("Date to Disable Account should not be the Past Date");
g_form.showFieldMsg('date_to_disable_account', 'Date to Disable Account should not be the Past Date', 'error');
g_form.clearValue('date_to_disable_account');
}
}
}
See, addErrorMessage is working fine, but it displays an error msg at the top of the catalog form (which is not desired) and clears this variable date value (which is functioning fine).
I want to display an error message just below the variable (date_to_disable_account) on the catalog form, so I used showFieldMsg and tested in catalog form by choosing any past date and found it functions only to clear the date value but NOT DISPLAYING any error field message in the highlighted area (below the variable).
Requesting to please help to get field message (error) display below the variable.
Thank You
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 12:57 AM
Hi @rishabh31
Check with below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var disDate = new GlideAjax('validateDisableDate');
disDate.addParam('sysparm_name', 'nowDateTime');
disDate.addParam('sysparm_disable_date', g_form.getValue('date_to_disable_account'));
disDate.getXML(compareDisableDate);
function compareDisableDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer < 0) { //To allow current date but not past date
//g_form.addErrorMessage("Date to Disable Account should not be the Past Date");
g_form.clearValue('date_to_disable_account');
g_form.showFieldMsg('date_to_disable_account', 'Date to Disable Account should not be the Past Date', 'error');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 01:32 AM
Hi @rishabh31 ,
Can you please try with:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var disDate = new GlideAjax('validateDisableDate');
disDate.addParam('sysparm_name', 'nowDateTime');
disDate.addParam('sysparm_disable_date', g_form.getValue('date_to_disable_account'));
disDate.getXML(compareDisableDate);
function compareDisableDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (parseInt(answer) < 0) { //To allow current date but not past date
g_form.clearValue('date_to_disable_account');
g_form.showFieldMsg('date_to_disable_account', 'Date to Disable Account should not be the Past Date', 'error');
}
}
}
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 12:57 AM
Hi @rishabh31
Check with below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var disDate = new GlideAjax('validateDisableDate');
disDate.addParam('sysparm_name', 'nowDateTime');
disDate.addParam('sysparm_disable_date', g_form.getValue('date_to_disable_account'));
disDate.getXML(compareDisableDate);
function compareDisableDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer < 0) { //To allow current date but not past date
//g_form.addErrorMessage("Date to Disable Account should not be the Past Date");
g_form.clearValue('date_to_disable_account');
g_form.showFieldMsg('date_to_disable_account', 'Date to Disable Account should not be the Past Date', 'error');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 01:33 AM
Hi @Manmohan K ,
Thank You🙂, your provided script where lines just interchanged is working fine.
But I am wondering why earlier it was not working as all things (syntax, method etc) are correct, so how does interchanging the lines make it work, please explain.
Marking your response as correct and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 01:39 AM
If you try to clear the value using g_form.clearValue(..) straight after the g_form.showFieldMsg(..) it will not display the error message as clearValue overrides the changes done by showFieldMsg function.
Instead clear the value prior to displaying the error message for getting expected results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 01:32 AM
Hi @rishabh31 ,
Can you please try with:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var disDate = new GlideAjax('validateDisableDate');
disDate.addParam('sysparm_name', 'nowDateTime');
disDate.addParam('sysparm_disable_date', g_form.getValue('date_to_disable_account'));
disDate.getXML(compareDisableDate);
function compareDisableDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (parseInt(answer) < 0) { //To allow current date but not past date
g_form.clearValue('date_to_disable_account');
g_form.showFieldMsg('date_to_disable_account', 'Date to Disable Account should not be the Past Date', 'error');
}
}
}
Thanks and Regards,
Rahul