How to get and set data Types In JavaScript?

 How to get and set data Types In JavaScript?


function changefield(executionContext) {


    var formContext = executionContext.getFormContext();


    //  Single line text Get


    var name = formContext.getAttribute("new_name").getValue();


     //  Single line text Set


    formContext.getAttribute("new_name").setValue("bharath");


    alert(name);


    //phonenumber get


    var mobile = formContext.getAttribute("new_mobile").getValue();


    //phonenumber set


    formContext.getAttribute("new_mobile").setValue("9078675645");


    alert(mobile);


    //two option get


    var gender = formContext.getAttribute("new_gender").getValue();


    //two option set


    formContext.getAttribute("new_gender").setValue(true);


    alert(gender);


    //date get


    var dob = formContext.getAttribute("new_dob").getValue();


    var dob = new Date("05/07/1996");


    //date set


    formContext.getAttribute("new_dob").setValue(dob);


    alert(dob);


    //option get


    var country = formContext.getAttribute("new_country").getText();


    //option set


    formContext.getAttribute("new_country").setValue(100000000);


    alert(country);


    //Multi select option set and get


    //Multi select option get values:

    formContext.getAttribute("new_countrystates").getValue();


    // Multi select option get Text:

    formContext.getAttribute("new_countrystates").getText();


    // Multi Select Option set using value

    formContext.getAttribute("new_countrystates").setValue([100000000, 100000002, 100000003]);


    // Multi - Select Option set using Text


    var common = [];

    var optionText = ["ANDHRA", "UP", "MP"];

    var optionSetValues = formContext.getAttribute("new_countrystates").getOptions();

    for (i = 0; i < optionText.length; i++) {

        for (j = 0; j < optionSetValues.length; j++) {

            if (optionText[i] === optionSetValues[j].text) {

                common.push(optionSetValues[j].value);

                formContext.getAttribute("new_countrystates").setValue(common);

            }

        }

    }


    //float get


    var weight = formContext.getAttribute("new_weight").getValue();


    //float set


    formContext.getAttribute("new_weight").setValue(2345.45);


    alert(weight);


    //Whole Number get 


    var age = formContext.getAttribute("new_age").getValue();


    //Whole Number set 


    formContext.getAttribute("new_age").setValue(24);


    //money get


    var amount = formContext.getAttribute("new_amount").getValue();


    //money set


    formContext.getAttribute("new_amount").setValue(3400);


    alert(amount);


    //multiline get value


    var description = formContext.getAttribute("new_annualsal").getValue();


    //multiline set value


    formContext.getAttribute("new_annualsal").setValue("HelloWorld");


    alert(description);


    //lookup get value



    //var account = formContext.getAttribute("new_lookvalue").getValue()[0].id;


    //var formContext = executionContext.getFormContext();

    var account = formContext.getAttribute("new_lookvalue").getValue()[0].id;

    var AuthorEntityType = formContext.getAttribute("new_lookvalue").getValue()[0].entityType;

    var AuthorName = formContext.getAttribute("new_lookvalue").getValue()[0].name;


    //declare array and create object for array


    //lookup set value


    var accountLookup = new Array();


    accountLookup[0] = new Object();


    //get the lookup guid from parent(account) entity


    accountLookup[0].id = "1d8b44cb-4c67-ee11-9ae6-000d3a0aabb1";


    //declare the parent entity name


    accountLookup[0].entityType = "account";


    //give the name of lookup field value


    accountLookup[0].name = "rakhaa";


    //setting lookup field value


    formContext.getAttribute("new_lookvalue").setValue(accountLookup);


    alert(account);


}

Comments

Popular posts from this blog

Relationship Behaviours in D365 crm

Call Action Through JavaScript

Power Apps Cheat Sheet