- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2018 09:22 PM
Hi All,
I have a mandatory field on my form and when I try to create/update a record without filling the data for Mandatory field I am getting error message, which is good. But the issue over here is that the error message is displayed on the screen Multiple times if I click on submit/update button multiple time without filling the data for Mandatory field as shown in below screenshot:
I have clicked twice on 'update' button without filling the mandatory field and hence the error is displayed twice. I want this error message to be displayed only once even if i click on update button multiple times. Can anyone please tell me how can I achieve this OR else can anyone help me to know where can I find the code that is displaying this error message(this will also be helpful).
Thanks & regards,
Mahendra Choudhary
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 09:27 PM
Hi All,
Thanks for you reply, the response from Nikhil was helpful, but still I wasn't able to achieve what I was looking for. Thanks for the link it didn't solved my issue, but gave me a hint. Below is my solution, by which I was able to achieve this:
There is much to explain about this issue, but could not write every thing over here.
field Name : Title (this was the field for which I was getting this issue. This field is mandatory in Dictionary)
In 'Save' button UI Action:
I have made the title field non-mandatory only if it is empty as follow:
if(!g_form.getValue('u_title'))
g_form.setMandatory('u_title', false);
in onSubmit Client script :
I have made the title field mandatory as follow: (if you don't do this then title field will be shown as non-mandatory)
g_form.setMandatory('title', true);
So now I am able to get my customized error message below the field by using 'g_form.showFieldMsg' instead of the ServiceNow default for field that is mandatory in dictionary. But now I was getting the message multiple times below title field if I click on submit button on form without filling the data, so below is the solution to fix this issue as well:
in onSubmit Client script:
I have hidden the previous message shown below the field and show new message as follow:
if(!g_form.getValue('title')) {
g_form.hideFieldMsg("title");
g_form.showFieldMsg("title", "Please enter the title for Alert", "error");
}
This resolved my issue. posting this solution here so that it may be helpful to someone else.
Thanks,
Mahendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2018 10:47 PM
Hello Upender Kumar,
I have face this issue when i was working on my project. that time my script goes in loop that's why its generating two message.
may be your correct.
Thanks,
Mohammed Iqbal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2018 10:01 PM
Hi Mahi,
in html / js its done like this
document.getElementById("mytext").focus();
so if there is a variable, you'' have to find its atcual ID eg.IO:6868 (by clicking on view source page
or inspect element F11)
and use it
document.getElementById("IO:0989078904645645").focus();
but this'll not work in Portal..
.focus() method is not build on SN, due to some very good reason..
so I would suggest avoid using it and use the pop-up message
Still, in SN you can use the in- build method showFieldMsg
you may try the below code too..
document.getElementById('sys_original.incident.number').focus();
Please look into relevant details using following link.
https://community.servicenow.com/community?id=community_question&sys_id=25e15faddbdcdbc01dcaf3231f961926
I believe it will help you, please mark this post correct and helpful.
Thanks,
Nikhil Dixit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2018 10:05 PM
Hi,
Yes, dear you are write this is issue with ServiceNow validation script.
It should first clear existing messages.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2018 10:05 PM
Hi Mahi,
in html / js its done like this
document.getElementById("mytext").focus();
so if theres a varible, you'' have to find its atcual ID eg.IO:6868 (by clicking on view source page
or inspect element F11)
and use it
document.getElementById("IO:0989078904645645").focus();
but this'll not work in Portal..
.focus() method is not build on SN, due to some very good reason..
so I would suggest avoid using it and use the pop-up message
Still, in SN you can use the in- build method showFieldMsg
you may try the below code too..
document.getElementById('sys_original.incident.number').focus();
Please look into more relevant information by using following link.
I believe it will help you. Please mark this post correct and helpful.
Thanks,
Nikhil Dixit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2018 10:07 PM
I missed to mention link above.
Here it is...
https://community.servicenow.com/community?id=community_question&sys_id=25e15faddbdcdbc01dcaf3231f961926
Thanks,
Nikhil Dixit