How to make ui formatter variables editable and mandatory

vikaskv
Tera Contributor

I have created record producer variables and populated those variables in target table using ui formatter i have make the fields in variables mandatory and editable in target table.
pleease refer to my screenshot and guide me through

7 REPLIES 7

Hey @Shraddha Kadam Thanks for the reply 

But as per requirement i need to create ui action button based on click of button that  fields should be mandatory and editable 

Hello @vikaskv ,

 

Please use the code below to make the variable mandatory using UI Action. 

function makeVariableMandatoryAndSubmit() {
    var variableName = 'contact_me'; // Replace with the actual variable name
    var variableValue = g_form.getValue(variableName);
	alert('Variable - '+variableValue);

    // Check if the variable is empty
   
        // Make the variable mandatory
        g_form.setMandatory(variableName, true);
        // Display an error message
        g_form.addErrorMessage('Please fill in the "' + g_form.getLabelOf(variableName) + '" field before proceeding.');
        return false; // Prevent form submission
    
}

 

Make sure the Client checkbox is true and in the Onclick field use "makeVariableMandatoryAndSubmit()" function.

Above code worked for me

If my response was helpful, please mark it as correct and helpful.
Thank you.

Ankur Bawiskar
Tera Patron
Tera Patron

@vikaskv 

you can create a client side UI action on your table and then use this syntax to make variables mandatory

g_form.setReadonly('variables.variableName', false);
g_form.setMandatory('variables.variableName', true);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader