Get and Set values of Data Types in Microsoft Dynamics CRM Using Java Script

Get and Set values of Data Types in Microsoft Dynamics CRM

Using Java Script

There are 13 datatype available in Dynamics 365.

  1. Single Line of Text
  • Multiple Line of Text
  • Option Set
  • Two Options
  • Lookup
  • Decimal
  • Date and Time
  • Whole Number
  • Floating Point Number
  • Currency
  • Multi Select Option Set
  • Image
  • Customer

 

The following statements guide you on how to get and set the respective values.

 

1.Datatype: Single Line of Text (or) Multiple Line Of Text

 

 

    • Get Value:

var str = Xrm.Page.getAttribute(“attribute logical name”).getValue();

        • Ex :  Var str = Xrm.Page.getAttribute(“new_singleline”).getValue();
    • Set Value:

Xrm.Page.getAttribute(“attribute logical name”).setValue(“Test”);

        • Ex : Xrm.Page.getAttribute(“new_txtsingleline”).setValue(“Test”);

2. Datatype: Option Set

 

 

    • Get Value:

var Opvalue = Xrm.Page.getAttribute(“attribute logical name”).getValue();

        • This will return selected option value.
        • Ex : Var Opvalue = Xrm.Page.getAttribute(“new_optionset”).getValue();
      • var Optext = Xrm.Page.getAttribute(“attribute logical name”).getText();
        • This will return selected text value .Like Vendor,Customer,Retailer
        • Ex :  Var Optext = Xrm.Page.getAttribute(“new_optionset”).getText();
    • Set Value: (Option Set)
      • Xrm.Page.getAttribute(“attribute logical name”).setValue(1);
        • Ex : Xrm.Page.getAttribute(“new_txtoptionset”).setValue(1);

 

 

Datatype: Two Options

 

 

    • Get Value:

var TwoOpvalue = Xrm.Page.getAttribute(“attribute logical name”).getValue();

        • This will return true or false
        • Ex : Xrm.Page.getAttribute(“new_twooptions”).getValue();

var TwoOptext = Xrm.Page.getAttribute(“attribute logical name”).getText();

        • This will return selected text value .Like yes or No.
        • Ex : Var TwoOptext=Xrm.Page.getAttribute(“new_twooptions”).getText();
    • Set Value: (Two Options)

Xrm.Page.getAttribute(“attribute logical name”).setValue(TwoOpvalue);

        • Ex : Xrm.Page.getAttribute(“new_txttwooptions”).setValue(TwoOpvalue);

 

  • 4. Datatype: Lookup

 

    • Get Value:

var lookupValue = Xrm.Page.getAttribute(“attribute logical name”).getValue();

var ID= lookupValue [0].id;

        • Will return id of the selected record.

var Name= lookupValue[0].name;

        • Will return selected text value.

var LogicalName= lookupValue[0].entityType;

        • Will return selected record logical name.

Ex : var lookupValue = Xrm.Page.getAttribute(“new_txtlookup”).getValue();

 

    • Set Value: (Lookup Field)

Xrm.Page.getAttribute(“attribute logical name “).setValue([{ id: “record Guid”, name:“recordname(Optional)”, entityType: “entity logical name” }]);

Ex : Xrm.Page.getAttribute(“new_txtlookup”).setValue([{ id: ID, name: Name, entityType: LogicalName}]);

Or

 

Var lookupval=new Array();

lookupVal[0] = new Object();

lookupVal[0].id = Id;

lookupVal[0].name = Name;

lookupVal[0].entityType =LogicalName;

 

   Xrm.Page.getAttribute(“new_parentcustomerid2”).setValue(lookupVal);

5. Datatype: Decimal

 

    • Get Value:
      • var decvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
        • Ex : Var decvalue= Xrm.Page.getAttribute(“new_decimal”).getValue();
    • Set Value:
      • Xrm.Page.getAttribute(“attribute logical name”).setValue(decvalue);
        • Ex : Xrm.Page.getAttribute(“new_txtdecimal”).setValue(decvalue);

6. Datatype: Date and Time

 

    • Get Value:
      • var datetime= Xrm.Page.getAttribute(“attribute logical name”).getValue();
        • Ex: var datetime= Xrm.Page.getAttribute(“new_datetime”).getValue();
    • Set Value:
      • Xrm.Page.getAttribute(“attribute logical name”).setValue(datetime);
        • Ex : Xrm.Page.getAttribute(“new_txtdatetime”).setValue(datetime);

7. Datatype: Whole Number

 

    • Get Value:
      • var Wholevalue = Xrm.Page.getAttribute(“attribute logical name”).getValue();
        • Ex : Var Wholevalue = Xrm.Page.getAttribute(“new_wholenumber”).getValue();
    • Set Value:
      • Xrm.Page.getAttribute(“attribute logical name”).setValue(Wholevalue);
        • Ex : Xrm.Page.getAttribute(“new_txtwholenumber”).setValue(Wholevalue);

8. Datatype: Floating Point Number

 

    • Get Value:
      • var Floatvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
        • Ex : Var Floatvalue= Xrm.Page.getAttribute(“new_floatnumber”).getValue();
    • Set Value:
      • Xrm.Page.getAttribute(“attribute logical name”).setValue(Floatvalue);
        • Ex : Xrm.Page.getAttribute(“new_txtfloatnumber”).setValue(Floatvalue);

9. Datatype: Currency

 

    • Get Value:
      • var Currencyvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
        • Ex : var Currencyvalue= Xrm.Page.getAttribute(“new_currency”).getValue();
    • Set Value:
      • Xrm.Page.getAttribute(“attribute logical name”).setValue(Currencyvalue);
        • Ex: Xrm.Page.getAttribute(“new_txtcurrencyvalue”).setValue(Currencyvalue);

10. Datatype: Multi Select OptionSet

 

    • Get Value:
      • var Mulopvalue= Xrm.Page.getAttribute(“attribute logical name”).getValue();
        • Ex : var Mulopvalue= Xrm.Page.getAttribute(“new_multiselectoptionset”).getValue();
    • Set Value:
      • Xrm.Page.getAttribute(“attribute logical name”).setValue(Mulopvalue);
        • Ex : Xrm.Page.getAttribute(“new_txtmulopvalue”).setValue(Mulopvalue);

11. Datatype : Customer

 

Customer datatype is similar to lookup but it contains only account and contact entity type only.

    • Get Value:

var lookupValue = Xrm.Page.getAttribute(“attribute logical name”).getValue();

var ID= lookupValue [0].id;

        • Will return id of the selected record.

var Name= lookupValue[0].name;

        • Will return selected text value.

var LogicalName= lookupValue[0].entityType;

        • Will return selected record logical name.

Ex : var lookupValue = Xrm.Page.getAttribute(“new_txtlookup”).getValue();

 

    • Set Value: (Lookup Field)

Xrm.Page.getAttribute(“attribute logical name “).setValue([{ id: “record Guid”, name:“recordname(Optional)”, entityType: “entity logical name” }]);

Ex : Xrm.Page.getAttribute(“new_txtlookup”).setValue([{ id: ID, name: Name, entityType: LogicalName}]);

Or

Var lookupval=new Array();

     lookupVal[0] = new Object();

     lookupVal[0].id = Id;

     lookupVal[0].name = Name;

     lookupVal[0].entityType =LogicalName; // account or contact

     Xrm.Page.getAttribute(“new_parentcustomerid2”).setValue(lookupVal);

 

Leave a Reply

Your email address will not be published. Required fields are marked *

twenty + eight =

Leave a Comment