Fields Mandatory

Naveen87
Tera Guru

Hello Developers,

 

I wanted to make few fields mandatory while closing the stask.

I used below script & it is working fine.

But I also want to add few things like, If user is in a different view where these fields are not visible on form then these should not be mandatory.

 

Do we have any line of code which check, If these fields are on the form?

If yes, then fill them(mandatory)

If No, ignore (non-mandatory)

Naveen87_0-1724663053421.png

function onSubmit() {
    //Type appropriate comment here, and begin script below

    var state = g_form.getValue('state');
    var solution = g_form.getValue('u_solution');
    var assign = g_form.getValue('assigned_to');

    if ((state == 3 || state == 10) && (solution == '')) {
        g_form.showFieldMsg('u_solution', 'Please fill solution before closing the Task', 'error');
        //	alert('Please fill solution field before closing the Task');
        return false;
    }
    if ((state == 3 || state == 10) && assign == '') {
        g_form.showFieldMsg('assigned_to', 'Please fill Assigned to before closing the Task', 'error');
        return false;
    }

}

 

Thank you

 

1 ACCEPTED SOLUTION

You can use the below like to check if the field is present on the form(current view)

 

 g_form.hasField('<your field name>') //returns true fi field is present, false if it is not

-Anurag

View solution in original post

14 REPLIES 14

No,

I gave you a script that will tell you whether the field is present on the form or not.

 g_form.hasField('<your field name>') //returns true fi field is present, false if it is not

-Anurag

Gurpreet07
Mega Sage

Hi Naveen,  You can simply uncheck the Global checkbox and then you can specify the view on which you want to run this script on.  

Can't have it for Default view.

Naveen87_0-1724667241867.png

 

Something like this is required.

var fields = ['field1','field2'];

if(g_form.hasField(field1=='xxx') && if(g_form.hasField(field2=='yyy')

For default view , uncheck the global and leave the view field empty

Naveen87
Tera Guru

Hello All,

 

I just found that it's happening from a UI action script & not due to client script.

Please suggest me code of line on this 1

Naveen87_1-1724668253366.png