- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2018 09:45 AM
How can I enforce mandatory field check in a client-side UI action?
I've tried putting 'g_form.checkMandatory = true;'
inside my function that is called on click and I want a check just like 'Save' UI Action, it should not allow further action if mandatory fields are not filled.
Thanks in advance!
Rishi
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2018 07:05 AM
There is one way to do this using below client side ui action :
if(g_form.mandatoryCheck() == true)
{
return false;
}
else return true;
Hope it helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2018 09:56 AM
Hello Rishi
Use the code like this:
if(g_form.getValue("mandatory field 1") == "" && g_form.getValue("mandatory field 2") == "")
{
return false;
}
else
{
return true;
}
Thanks
Abhijeet Upadhyay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2018 10:57 PM
This is certainly a way but I don't want to use it as my form has 40 fields and 10 UI Policies for different conditions.
There is a better way to do this by using g_form.getMissingFields(); but this is still not the solution I am looking for.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2018 11:01 PM
thanks for your response. I have a different approach as well and will respond back shortly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2018 11:32 PM
UI Action:
onclick: check_mandattory()
Script:
function check_mandattory()
{
var table = "table_name"; // name of the table comes here
var ga = new GlideAjax("mandatory")
ga.addParam("sysparm_name", "mandatory");
ga.addParam("sysparm_table", table);
ga.getXMLWait();
var answer = ga.getAnswer();
answer = answer.split(",");
var flag = false;
for(var i = 0; i < answer.length-1; i++)
{
if(g_form.getValue(answer[i]) == "")
{
flag = true;
break;
}
}
if(flag == true)
{
return false;
}
else
{
return true;
}
}
Script Include:
Name: mandatory
Script:
var mandatory = Class.create();
mandatory.prototype = Object.extendsObject(AbstractAjaxProcessor, {
mandatory: function() {
var table = this.getParameter(sysparm_table);
var answer = "";
var gr = new GlideRecord("sys_dictionary");
gr.addQuery("name", table);
gr.addQuery("mandatory", true);
gr.query();
while(gr.next())
{
answer = answer + gr.column_name + ",";
}
return answer;
},
type: 'mandatory'
});