Code Snippets

  • Form Pre-Fill values
    JavaScript
    Presetting form fields with JavaScript in Dynamics 365
Presetting form fields with JavaScript in Dynamics 365 allows developers to programmatically populate default values in specific fields when a form is loaded.

// Prefill fields in Dynamics 365 formsss function prefillFieldsOnNewForm(executionContext) { const formContext = executionContext.getFormContext(); // Get the form context const formType = formContext.ui.getFormType(); // Get the form type (1 = Create) // Check if the form type is "Create" if (formType === 1) { // Prefill the text field formContext.getAttribute("pps_textfield").setValue("Default Text"); // Prefill the integer field formContext.getAttribute("pps_integerfield").setValue(100); // Prefill the option set field (value must correspond to an existing option's value) formContext.getAttribute("pps_optionsetfield").setValue(1); // Prefill the date field with the current date formContext.getAttribute("pps_datefield").setValue(new Date()); } }