formContext.getAttribute(): Returns the attribute object for the specified attribute.
Example:
Suppose we have a custom field called “new_email1” on the Contact entity form and we want to get the value of this field using JavaScript code.
we can use the formContext.getAttribute() function to get the attribute object for the “new_ email1” field, and then use the getValue() method to get the value of the field.
var email1 = formContext.getAttribute(“new_email1”);
if(email1!= null && email1.getValue() != null){
var email = email1.getValue();
console.log(“Email: ” + email);
}
In this example, the formContext object is assumed to be already defined and refers to the current form’s context.
The code first calls the formContext.getAttribute() function with the name of the attribute “new_email1”. If the attribute exists, it returns an Attribute object, which is stored in the email1 variable. Then, the code checks whether the email1 object is not null and whether it has a value. If both conditions are true, it gets the value of the attribute using the getValue() method, which is then logged to the console.
formContext object is only available on the form where the script is executed. If you want to access the same field from a different form or in a different context, you will need to use a different method.