官术网_书友最值得收藏!

Working with number fields

In this chapter, we will be working with a variation of the text field, and the number fields. By default, Dynamics CRM allows us a few fields with various number formats and data types associated.

The following field types are standard in Dynamics CRM:

  • Whole Number – this format includes values from -2,147,483,648 to 2,147,483,647 on the default format of None. Additional formats include the following:
    • Duration – this is a drop-down list box with values in minutes, hours and days
    • Time Zone – this is a drop-down list box with time zone options
    • Language – this is a drop-down list box of available languages for the user
  • Floating Point Number – this format includes values from 0 to 1,000,000,000 and the precision can be configured anywhere from 0 to 5 decimal places.
  • Decimal Number – while this format includes the same range of values as the floating point number, the precision can be configured from 0 to 10 decimal places.

Addressing these field types in script uses the same syntax, but we have to be aware of how we initially define them, as the data type cannot be changed after creation.

Note

The only way to change the data type defined for a field is to remove the field from the form, publish the form, and then remove the field from the entity and republish it. Afterwards we can recreate the required field with the updated data type. Pay close attention when taking this approach, as trying to re-import the managed solution after this change will fail. The reason for this is that you are trying to do exactly what you were prevented from doing in the first place.

Getting ready

Open the solution from the previous recipe if not already opened. We will use the same solution package to store this new customization.

The client-side scripting is the same for these field types, and JavaScript will handle automatically the data type of the value we are reading.

How to do it...

In order to work with a number field follow these steps:

  1. Create a new form field, named new_number of type Whole Number, of default format None. Add it to the form.
  2. Add a new JScript resource named JSNumbers.js.
  3. Insert the following code:
    function ReadNumberField()
    {
       var myNumber;
       myNumber = Xrm.Page.getAttribute("new_number").getValue();
       alert("The number in the field is: " + myNumber);
    }
  4. Save and publish the resource.
  5. Attach the function to the OnChange event of the field. Save and publish the form again.
  6. Run the form and change the value in the field to 100. You should be getting the following popup:
    How to do it...

Reading a value from a number field is identical to reading a value from any other regular text field.

There's more...

The difference between these fields is in the data that we can push back in this field, for example, if we try the following code to add a text value to a field defined as a Whole Number:

   try
   {
    Xrm.Page.getAtribute("new_number").setValue("AAA");
   }
      catch(err)
   {
      alert("Error: " + err.message);
   }
主站蜘蛛池模板: 科技| 卢湾区| 莱芜市| 白银市| 阜新市| 澎湖县| 深泽县| 阿克陶县| 广灵县| 黄陵县| 宁晋县| 旬邑县| 正阳县| 米脂县| 陈巴尔虎旗| 鄂尔多斯市| 察隅县| 双城市| 汨罗市| 措美县| 伊春市| 灵璧县| 津市市| 漳州市| 林芝县| 尉氏县| 西平县| 邵东县| 乐至县| 遂溪县| 泰宁县| 大埔县| 苍溪县| 临沂市| 琼中| 台中市| 德兴市| 托克托县| 新巴尔虎右旗| 镇赉县| 渝中区|