Wednesday, July 9, 2025

Read/Get And Write/Update All Data Types Of Field Values Using Java Script Into Dynamics 365 CRM/CE

 // Read And Write The Dynamics 365 CRM All Data Types Of Field Using Java Script

function AllDataTypeReadAndWrite(executionContext) {

    debugger;
    var formContext = executionContext.getFormContext();

    // Read Single Line of Text Field
        var empName = formContext.getAttribute("min_name")?.getValue();

    // Read Multi Line of Text Field
        var empAddress = formContext.getAttribute("min_address")?.getValue();

    // Read Date and Time Field
        var empDOB = formContext.getAttribute("min_dob")?.getValue();

    // Read Two Option Field
        var areYouINterested = formContext.getAttribute("min_areyouintersted")?.getValue();

    // Read Optionset Field
        var empCountry = formContext.getAttribute("min_country")?.getValue();

    // Read Multiselect Optionset Field
        var empCourses = formContext.getAttribute("min_courses")?.getValue();

    // Read Whole Number Field
        var empPostalCode = formContext.getAttribute("min_postalcode")?.getValue();

    // Read Decimal Field
        var empPercentage = formContext.getAttribute("min_percentage")?.getValue();

    // Read Currency Field
       var empSalary = formContext.getAttribute("min_salary")?.getValue();

    // Read Lookup Field
        var org = formContext.getAttribute("min_organization")?.getValue();

        var orgid = org[0].id;
        var orgname = org[0].name;
        var orgentityname = org[0].entityType
;



// Set/Update Single Line of Text field

    if (empName !== null && empName !== undefined)
   {
       formContext.getAttribute("min_name1").setValue(empName);
   }

// Set/Update Multi  Line of Text field

    if (empAddress !== null && empAddress !== undefined)
   {
       formContext.getAttribute("min_address1").setValue(empAddress);
   }

// Set/Update Date and Time field

    if (empDOB !== null && empDOB !== undefined)
   {
       formContext.getAttribute("min_dob1").setValue(empDOB);
   }

// Set/Update Two Option field

    if (areYouINterested == true)
   {
       formContext.getAttribute("min_areyouinterested1").setValue(true);
   }

else {
       formContext.getAttribute("min_areyouinterested1").setValue(false);
   }

// Set/Update OptionSet field

    if (empCountry !== null && empCountry !== undefined)
    {
       formContext.getAttribute("min_country1").setValue(empCountry);
    }

// Set/Update Multi Select OptionSet field

    if (empCourses !== null && empCourses !== undefined)
   {
      formContext.getAttribute("min_courses1").setValue(empCourses);
   }

// Set/Update Whole Number field

    if (empPostalCode !== null && empPostalCode !== undefined)
    {
                             formContext.getAttribute("min_postalcode1").setValue(empPostalCode);
    }

// Set/Update Decimal field

    if (empPercentage !== null && empPercentage !== undefined)
    {
        formContext.getAttribute("min_percentage1").setValue(empPercentage);
     }

// Set/Update Currency field

    if (empSalary !== null && empSalary !== undefined)
    {
       formContext.getAttribute("min_salary1").setValue(empSalary);
    }

// Set/Update Lookup field

    if (org !== null && org !== undefined)
    {
       formContext.getAttribute("min_organization1").setValue([{ id: orgid, name: orgname, entityType: orgentityname }]);
    }

}

No comments:

Post a Comment

What Is A Column In Dynamics 365 CRM?

 In This Post we are going to Explain