Insert Data to currency exchange rate (using Webservice)

julkifli33julkifli33 Member Posts: 1,085
edited 2014-06-20 in NAV Three Tier
Hi All...
i created application to insert data to table
using C# web services
i can insert to other table such as : GL Account, Vendor, Customer, etc...
these all no problem...

but when i import to Currency Exchange Rate (Table 330)
it wont get in ... the problem is from my txt file, cant be inserted to Starting Date field
the error message is
09/05/2012 5:20:23 PM Testing Company ==> *** The Currency Exchange Rate already exists. Identification fields and values: Currency Code='USD',Starting Date=''
it shows Starting date is blank, whereas i tried using hardcode "01/01/2012" also cannot

please help
thanks

Comments

  • thegunzothegunzo Member Posts: 274
    When you say "hardcode" for the date, where did you do that ?

    It is obvious from the error message that the date is not in the required field when you try to install the record. For more help, you will have to show more of your code and data.
    ________________________________
    Gunnar Gestsson
    Microsoft Certified IT Professional
    Dynamics NAV MVP
    http://www.dynamics.is
    http://Objects4NAV.com
  • julkifli33julkifli33 Member Posts: 1,085
    thegunzo wrote:
    When you say "hardcode" for the date, where did you do that ?

    It is obvious from the error message that the date is not in the required field when you try to install the record. For more help, you will have to show more of your code and data.

    This is my C# code
    //Create New ExchangeRate
    UpdateExchangeRate = new ExchangeRatePageRef.ExchangeRate_Nav();                               
    DateTime ds = Convert.ToDateTime("01/01/2013");
    UpdateExchangeRate.Currency_Code = ExchangeRateValues[0];                                
    UpdateExchangeRate.Starting_Date = ds;                              
    MessageBox.Show(ds.ToShortDateString(), "test");
    ExchangeRateService.Create(ref UpdateExchangeRate);
    ExchangeRateService.Update(ref UpdateExchangeRate);
    

    from this code it can capture 01/01/2013, but i cant insert to database
    MessageBox.Show(ds.ToShortDateString(), "test");
    

    is it because currency exchange rate table has 2 primary keys???
  • thegunzothegunzo Member Posts: 274
    Hi again

    I wanted to test this and the first thing that I had to do was to change the Editable property for field Currency Code in page 483 to TRUE.

    Then I tried
    UpdateExchangeRate.Currency_Code = "EUR"
            UpdateExchangeRate.Starting_Date = ds
            UpdateExchangeRate.Starting_DateSpecified = True
            ExchangeRatePage.Create(UpdateExchangeRate)
    
    and only after adding the line
    UpdateExchangeRate.Starting_DateSpecified = True
    

    the date was inserted into the data.
    ________________________________
    Gunnar Gestsson
    Microsoft Certified IT Professional
    Dynamics NAV MVP
    http://www.dynamics.is
    http://Objects4NAV.com
  • julkifli33julkifli33 Member Posts: 1,085
    thegunzo wrote:
    Hi again

    I wanted to test this and the first thing that I had to do was to change the Editable property for field Currency Code in page 483 to TRUE.

    Then I tried
    UpdateExchangeRate.Currency_Code = "EUR"
            UpdateExchangeRate.Starting_Date = ds
            UpdateExchangeRate.Starting_DateSpecified = True
            ExchangeRatePage.Create(UpdateExchangeRate)
    
    and only after adding the line
    UpdateExchangeRate.Starting_DateSpecified = True
    

    the date was inserted into the data.

    hi thegunzo !
    thanks ! it works
    1 more question
    how to filter starting date with string

    because before do the process, i do search...
    if find then modify... if not then add
    but everything will goes to add process
    //Filtering Currency Code
    ExchangeRatePageRef.ExchangeRate_Nav_Filter filterExchangeRate0 = new ExchangeRatePageRef.ExchangeRate_Nav_Filter();
    filterExchangeRate0.Field = ExchangeRatePageRef.ExchangeRate_Nav_Fields.Currency_Code;
    filterExchangeRate0.Criteria = ExchangeRateValues[0];
    
    //Filtering Starting Date
    ExchangeRatePageRef.ExchangeRate_Nav_Filter filterExchangeRate1 = new ExchangeRatePageRef.ExchangeRate_Nav_Filter();
    filterExchangeRate1.Field = ExchangeRatePageRef.ExchangeRate_Nav_Fields.Starting_Date;
    [b]filterExchangeRate1.Criteria = ExchangeRateValues[1];[/b]
    
    ExchangeRatePageRef.ExchangeRate_Nav_Filter[] filterExchangeRateno = new [b]ExchangeRatePageRef.ExchangeRate_Nav_Filter[] { filterExchangeRate0,filterExchangeRate1};[/b]
    ExchangeRatePageRef.ExchangeRate_Nav[] ExchangeRatesModify = ExchangeRateService.ReadMultiple(filterExchangeRateno, null, 0);
                                                      
                                bool found = false;
                                foreach (ExchangeRatePageRef.ExchangeRate_Nav ExchangeRateChild in ExchangeRatesModify)
                                {                                                           
                                    //Modify ExchangeRate 
                                    if (ExchangeRateChild != null)
                                    {                                   
                                        found = true;                                    
                                       UpdateExchangeRate = ExchangeRateService.Read(ExchangeRateValues[0], Convert.ToDateTime(ExchangeRateValues[1])); 
    .
    .
    .
    .
    .
    .
    
  • lvanvugtlvanvugt Member Posts: 774
    UpdateExchangeRate.Starting_DateSpecified = True
    

    Hi guys,

    Any of you found out why this line is actually needed and where from the Starting_DateSpecified is coming (as it is typically no field or function on te Exchange Rate table)?
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • ssinglassingla Member Posts: 2,973
    A post on MSDN http://social.msdn.microsoft.com/Forums/vstudio/en-US/a1bca402-cbe1-4233-8eb3-ce01b8cefcd4/parameter-names-ending-with-specified-added-to-web-service-method-call?forum=wcf
    says this

    "Specified" fields are only generated on optional parameters that are structs. (int, datetime, decimal etc). All such variables will have additional variable generated with the name <variableName>Specified.

    This is a way of knowing if a parameter is really passed between the client and the server.

    To elaborate, an optional integer, if not passed, would still have the dafault value of 0. How do you differentiate between this and the one that was actually passed with a value 0 ? The "specified" field lets you know if the optional integer is passed or not. If the "specified" field is false, the value is not passed across. If it true, the integer is passed.
    CA Sandeep Singla
    http://ssdynamics.co.in
  • lvanvugtlvanvugt Member Posts: 774
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
Sign In or Register to comment.