JavaScript - Show-Hide/ Lock-Unlock/ Required-NotRequired

JavaScript syntax to show Hide different controls : 


function showHide(executionContext) {
    var formContext = executionContext.getFormContext();

    //showHide field
    formContext.getControl("new_field").setVisible(false);
    formContext.getControl("new_field").setVisible(true);

    //showHide tab
    formContext.ui.tabs.get("tab_tabname").setVisible(false);
    formContext.ui.tabs.get("tab_tabname").setVisible(true)


    //showHide section
    formContext.ui.tabs.get("tab_tabname").sections.get("sectionName").setVisible(false);
    formContext.ui.tabs.get("tab_tabname").sections.get("sectionName").setVisible(true);

    //ShowHide related entity from related section
    var navItem = formContext.ui.navigation.items.get("Courses");
    if (navItem) {
        navItem.setVisible(false);
    }
}

JavaScript Syntax to lock-unlock fields -

function lockUnlock(executionContext) 
{
var formContext = executionContext.getFormContext();

//lock-unlock field
formContext.getControl("new_field").setDisabled(false);
formContext.getControl("new_field").setDisabled(true);

}
JavaScript Syntax to make field mandatory or non madatory


function mandatoryField(executionContext) {
    var formContext = executionContext.getFormContext();

    //required- not required field
    formContext.getAttribute("new_field").setRequiredLevel("none");
    formContext.getControl("new_field").setRequiredLevel("required");
}

Comments

Popular posts from this blog

Accessing Fields on QuickView Form through javaScript

Custom Subgrid Using HTML Web resource

Check Dirty Fields or Forms in Dynamics 365