Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to make fields mandatory in ui action

test1231998
Tera Contributor

I have to make work notes and closed notes mandatory when I click on closed in Problem.So I have created a ui action for this.How can I add the conditions to make fields mandatory in this ui action.This is not working Can anyone please suggest and I am also not able to get the field name for work notes

find_real_file.png

5 REPLIES 5

RiteshSwarnakar
Giga Guru

UI Action

 
Active : true
Show update : true
Client : true
List v2 Compatible : true
List v3 Compatible : true

Onclick: setM();

 

 

function setM() {

    var c = 0;
    var arr = ['fieldname1','fieldname2','variables.variablename1','variables.variablename2'];
    for (var i = 0; i < arr.length; i++) {
        if (g_form.getValue(arr[i]) == '') {
            g_form.setMandatory(arr[i], true);
            c++;
        }
    }
	
	if (c>0){
		alert('Please fill Mandatory fields');
	}

    var mrvs = g_form.getValue('mrvs_name');
    var data = JSON.parse(mrvs);
    if (data.length == 0) {
        alert('MRVS cannot be empty!');
    }

    if (c == 0 && data.length > 0)  {
        g_form.setValue('state', 'submit');
        g_form.save();
    }
}