Enforce Mandatory fields on a client-side UI action

Rishi18
Kilo Expert

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

 

1 ACCEPTED SOLUTION

Inactive_Us1474
Giga Guru

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.

 

View solution in original post

12 REPLIES 12

Abhijeet Upadhy
Tera Expert

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

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.

thanks for your response. I have a different approach as well and will respond back shortly.

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'
});