locked
Create Money field attribute RRS feed

  • Question

  • Hi all,

    I have a custom entity called 'Employee Details' which contains salary as attribute. Now I want to create records by using SDK. I have n no.of attributes but salary i declared as a money data type and Date of join as datetime datatype. I am getting problem with these two fields. How can i insert these two attributes. I have written the code as follows.

                StringProperty sal = new StringProperty();
                sal.Name = "new_salary";
                sal.Value = TextBox4.Text;
                StringProperty doj = new StringProperty();
                doj.Name = "new_dateofjoin";
                doj.Value = TextBox5.Text;

    Please help me.

    Regards,
    GF

    Thursday, July 16, 2009 5:36 AM

Answers

  • You can do like this

    CrmMoney sal = new CrmMoney;
    sal.Value = Convert.ToDecimal(TextBox4.Text);
    CrmMoneyProperty salProperty = New CrmMoneyProperty
    salProperty.Value = sal;
    salProperty.Name = "new_salary";

    and same for CRm money field


    Dare to promise
    • Proposed as answer by D-Virdi Thursday, July 16, 2009 5:52 AM
    • Marked as answer by Golden Fish Thursday, July 16, 2009 11:17 AM
    Thursday, July 16, 2009 5:51 AM
  • Hi,

    Couldn't you use something like this


                PicklistProperty myPP = new PicklistProperty();
                myPP.Name = "nameOfPicklistAttribute";
    // text of picklist
                myPP.Value.name = "name";
    // value of picklist
                myPP.Value.Value = 4;

    Regards,
    Nishant rana
    http://nishantrana.wordpress.com
    • Marked as answer by Golden Fish Thursday, July 16, 2009 11:17 AM
    Thursday, July 16, 2009 10:54 AM

All replies

  • Hi,

    You'll need to use

       CrmMoneyProperty and CrmDateTimeProperty inplace of StringProperty.

    Regards,
    Nishant Rana
    http://nishantrana.wordpress.com
    Thursday, July 16, 2009 5:38 AM
  • In that case I am getting error at  doj.Value = TextBox5.Text; this line like 'can not convert CrmMoney to string. If possible please give me code for all data types like for picklist, bit, money, datetime etc.,
    Thursday, July 16, 2009 5:40 AM
  • Hi,

    Do this

           CrmMoneyProperty doj = new CrmMoneyProperty();
           doj .Value.Value = Convert.ToDecimal(TextBox5.Text );

    Regards,
    Nishant  Rana
    http://nishantrana.wordpress.com
    Thursday, July 16, 2009 5:45 AM
  • You can do like this

    CrmMoney sal = new CrmMoney;
    sal.Value = Convert.ToDecimal(TextBox4.Text);
    CrmMoneyProperty salProperty = New CrmMoneyProperty
    salProperty.Value = sal;
    salProperty.Name = "new_salary";

    and same for CRm money field


    Dare to promise
    • Proposed as answer by D-Virdi Thursday, July 16, 2009 5:52 AM
    • Marked as answer by Golden Fish Thursday, July 16, 2009 11:17 AM
    Thursday, July 16, 2009 5:51 AM
  • Hi nishant and deepak,

    By using above code it executes successfully but the salary field is not updated. The value what I given in text box is not inserted in CRM. for all other fields its working fine like string fields.

    Regards,
    GF
    Thursday, July 16, 2009 5:58 AM
  • It should work fine.. debug it and check the value in salary.
    Coding wise its fine
    Dare to promise
    Thursday, July 16, 2009 6:10 AM
  • Hi,

    while I creating a record from .net the currency symbol is not visible in front of money field. So, the money value is not inserted in that field. What could be the problem?.

    Regards,
    GF
    Thursday, July 16, 2009 7:08 AM
  • The currency sign is automatically added according to culture in CRM.
    no need to add in code.

    Dare to promise
    Thursday, July 16, 2009 8:36 AM
  • HI,

    How can i insert picklist values i.e., drop down list in .net.

    Regards,
    GF
    Thursday, July 16, 2009 9:44 AM
  • Hi,

    You would use InsertOptionValue message for that !

    http://msdn.microsoft.com/en-us/library/cc156300.aspx


    Regards,
    Nishant Rana
    http://nishantrana.wordpress.com
    Thursday, July 16, 2009 9:50 AM
  • I have created a picklist field 'Gender' in my custom entity. I have to create records that contains pick list value from .net application. How can i do it?.
    Thursday, July 16, 2009 10:23 AM
  • Hi,

    Couldn't you use something like this


                PicklistProperty myPP = new PicklistProperty();
                myPP.Name = "nameOfPicklistAttribute";
    // text of picklist
                myPP.Value.name = "name";
    // value of picklist
                myPP.Value.Value = 4;

    Regards,
    Nishant rana
    http://nishantrana.wordpress.com
    • Marked as answer by Golden Fish Thursday, July 16, 2009 11:17 AM
    Thursday, July 16, 2009 10:54 AM