Get and Set in MS Crm using JavaScript

 Getting the data from the form using JavaScript

in the JavaScript, for every data type common to get the data. there some difference, in Crm we have following type of data types. we will discuss one by one.

Single line of text, two option set, whole number, currency, decimal number, date and time, floating number, option set. for all these data types getting data is common.

fist we need to create function with name like below

for getValue return type is Number and for the getText return type is string 

function nameoffunction (executionContext){

// it will get the all the form data

var formContext =executionContext .getFormContext();

var variablename= formContext. getAttribute("Filedschemaname").getValue();

// for getting the text of option set 

var variablename= formContext. getAttribute("Filedschemaname").getText();

}

For the data type of lookup and customer we have a small chnage

 var lookupId = formContext. getAttribute("fieldname").getValue()[0].id;

 var lookupName =  formContext. getAttribute("fieldname").getValue()[0].name;

 var lookupEntityName =  formContext. getAttribute("fieldname").getValue()[0].entityType;

Setting the value single line and multiple line: 

 formContext. getAttribute("fieldname").setValue("your data");

Option set

 formContext. getAttribute("fieldname").setValue(pass the value of the backend value);

two option set 

 formContext. getAttribute("fieldname").setValue(true/false);

whole number: 

 formContext. getAttribute("fieldname").setValue( number data without decimal);

floating point number

formContext. getAttribute("fieldname").setValue( number data without  or with decimal);

decimal number

formContext. getAttribute("fieldname").setValue( number data without  or with decimal);

currency

formContext. getAttribute("fieldname").setValue( number data without  or with decimal);

Datetime

Date Objectname= new Date (pass year, month, date)

formContext. getAttribute("fieldname").setValue(Objectname );

Multi option set 

Set Multi Select Option set using value

formContext.getAttribute("vv_country").setValue([5333500000,5333500001,5333500002);

better to use value setting.

Set Multi-Select Option set using Text

  var Optionsets=[];

        var optionText = ["hyd","vizag","srikakulam"];

        var optionSetValues = formContext.getAttribute("vv_city").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("vv_city").setValue(Optionsets);

             }

         }

      }

Lookup and Customer data types

 var rLookup =new Array()

           rLookup [0]= new Object();

           rLookup [0].id = "guid of the record";  

           rLookup [0].entityType = "contact";            

           rLookup [0].name = "recrod name";            


formContext.getAttribute("vv_rlookup").setValue(rLookup); 


Thanks for reading my post. Add comment and follow the blog for the latest posts.

 

Comments

Popular posts from this blog

Connect MS Crm To Postman For Webapi Calls.

create HTML page show all contact related to specific account, add this webresource as a subgrid in the form

create one PCF control and embed into crm