Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

client script

AK001025799
Tera Expert

We need to list all the mandatory fields in the record using a client script (code)

1 ACCEPTED SOLUTION

Hi @AK001025799 ,
1.Create a onLoad client script.

Table - Incident

UI type - All

Type - onLoad

Active - checked

Global - Checked else specify viewName

Rakesh_M_0-1784038333715.png

2.Add the following script with a delay

function onLoad() {
    // Delay execution by 500ms to allow Dictionary Overrides to fully load in the browser
    setTimeout(function() {
        
        var fields = g_form.getEditableFields();
        var mandatoryFieldsList = [];

        for (var i = 0; i < fields.length; i++) {
            var fieldName = fields[i];
            
           
            if (g_form.isMandatory(fieldName)) {
               
                var fieldLabel = g_form.getLabelOf(fieldName);
                mandatoryFieldsList.push(fieldLabel);
            }
        }

        // If mandatory fields are found, display them 
        if (mandatoryFieldsList.length > 0) {
            g_form.addInfoMessage("The following fields are mandatory:\n\n" + mandatoryFieldsList.join(","));
        }
    }, 500); // 500 milliseconds delay
}

 

3.Save the record.

4.you will get a Info message on form load.

Rakesh_M_1-1784038557426.png

 

View solution in original post

15 REPLIES 15

Bhargavi Patel
Kilo Guru

Hi @AK001025799 

I think you can do this using an onLoad Client Script. I'm still learning, but this code worked for me.
function onLoad() {
var fields = g_form.getEditableFields();
var mandatory = [];

for (var i = 0; i < fields.length; i++) {
if (g_form.isMandatory(fields[i])) {
mandatory.push(g_form.getLabelOf(fields[i]));
}
}

alert("Mandatory Fields:\n" + mandatory.join("\n"));
}
This checks all the editable fields on the form and shows the mandatory field labels in an alert.

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.

No its not working

Danish Bhairag2
Tera Sage

Hi @AK001025799 ,

 

function onLoad() {

    var mandatoryFields = [];

    var elements = g_form.elements;

    for (var i = 0; i < elements.length; i++) {

        var fieldName = elements[i].fieldName || elements[i].name;

        if (fieldName && g_form.isMandatory(fieldName)) {
            mandatoryFields.push(fieldName);
        }
    }

    console.log("Mandatory Fields:", mandatoryFields);
    alert("Mandatory Fields:\n" + mandatoryFields.join("\n"));
}

 

Thanks,

Danish Bhairagdar

No, it's still not working