Dynamic CRM 2013 Learning Notes (17) JS Read and write various types of field methods and techniques

Source: Internet
Author: User

We often have to read or assign the various types of fields in the form, and the following lists the various types of reading and writing methods and considerations:

1. Lookup type

    • Empty value
var state = Xrm.Page.getAttribute ("new_state");
if null)
{
Xrm.Page.getAttribute ("new_state"). SetValue (null);
}

    • Read value
var New Array ();
State = Xrm.Page.getAttribute ("new_state"). GetValue ();
if null)
{
var statetext = state[0]. name;
var stateid = state[0].id;
var stateType = State[0].entitytype;
Alert ("" + statetext + "" + Stateid + "
of type: " + stateType);
}

Pay special attention to the value taken here, must add [0], or not get the value

    • Assign value
var New Array ();
New Object ();
State[0].id = "{ba0762e4-64d2-e111-909e-00155d6c871a}";
State[0]. name = "New York";
State[0].entitytype = "new_state";
Xrm.Page.getAttribute ("new_state"). SetValue (state);
2. Option Sets

    • Read value
var sval = Xrm.Page.getAttribute ("new_optionset"). Getselectedoption (). text;
var sval = Xrm.Page.getAttribute ("new_optionset"). Getselectedoption (). value;
Read display text and values, respectively
In addition, we can use the following method to get the text and value:
var sval = Xrm.Page.getAttribute ("new_optionset"). GetText ();
var sval = Xrm.Page.getAttribute ("new_optionset"). GetValue ();
    • Assign value

function Setosvalue (Osname, Oslabel)
{
var options = Xrm.Page.getAttribute (osname). GetOptions ();
 for (i = 0; i < options.) length; i++)
{
if (Options[i].text = = Oslabel)
Xrm.Page.getAttribute (Osname). SetValue (Options[i].value);
}
}
3. Datetime
    • Read value
var mycontactbirthday;
Mycontactbirthday = Xrm.Page.getAttribute ("birthdate"). GetValue ();
Alert ("" + mycontactbirthday);
var year = Mycontactbirthday.getfullyear ();
var //From 0 to one
var //from 1 to
Month = month + 1;
Alert ("+ year +""+ month +""+ Day");
    • Assign value
var New Date ();
Xrm.Page.getAttribute ("new_mydate"). SetValue (Currentdatetime);
4. Currency
    • Read value
var mycurrencyfield;
Mycurrencyfield = Xrm.Page.getAttribute ("new_currencyfield"). GetValue ();
Alert ("" + Mycurrencyfield);
    • Assign value
var mycurrencyvalue = 6.25;
Xrm.Page.getAttribute ("new_currencyfield"). SetValue (parsefloat(mycurrencyvalue));
5. Number, text
    • Read value
var mynumber;
MyNumber = Xrm.Page.getAttribute ("new_number"). GetValue ();
Alert ("" + mynumber);
    • Assign value
Xrm.Page.getAttribute ("new_text"). SetValue ("ABC");
Xrm.Page.getAttribute ("new_number"). SetValue (123);
Dynamic CRM 2013 Learning Notes Series Rollup

Dynamic CRM 2013 Learning Notes (17) JS Read and write various types of field methods and techniques

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.