Options

NAV 2013 R2: Webservice in NAV reading multiple records

MMVMMV Member Posts: 99
edited 2014-02-11 in NAV Three Tier
Dear All,

I have a requirement where in Webservice consuming application (.Net application) is sending multiple records to NAV. I am using a codeunit in NAV which has XMLPort as a Parameter (VAR). Below is the .Net Application code :

RootDimensions RootDim = new RootDimensions();
List<Dimension> DimList = new List<Dimension>();

if (dimInputCode.Text != "" && dimInputName.Text != "")
{
Dimension Dim = new Dimension();
Dim.DimensionCode = "AREA";
Dim.Code = "1000";
Dim.Name = "1000";
DimList.Add(Dim);

Dim = new Dimension();
Dim.Code = "1003";// dimInputCode.Text;
Dim.Name = "1003"; // dimInputName.Text;
Then we add the single dimension to our list
DimList.Add(Dim);

//To get the list of dimensions "attached" to the root element, we use the following
RootDim.Dimension = DimList.ToArray();
try
{
//Then we send to NAV and show our result
ResultLabel.Text = NAVImport.ImportDim(ref RootDim);
DimList.Clear();
}
catch (Exception ex)
{
//Show a possible exception
ResultLabel.Text = ex.ToString();
}

But when the system reads, the array contains only the last records but twice.

Any idea as to how to read multiple records using Webservice in NAV 2013 R2.

Best Regards,
MMV

Answers

  • Options
    mdPartnerNLmdPartnerNL Member Posts: 802
    don't you need to serialize your class first to a xml ?
  • Options
    MMVMMV Member Posts: 99
    Hi mdPartnerNL,

    The above code works well for a single record. But when I tried to add multiple records, it adds only the last record in the List array.

    Best Regards,
    MMV
  • Options
    einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Wouldn't it be much easier to just expose the Dimension List as Web Service and use the ReadMultiple method?
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • Options
    MMVMMV Member Posts: 99
    Hi einsTeIn.NET,

    Thank you for your reply. What is this ReadMultiple? I am using a Codeunit which is exposed and the Codeunit has a function "ImportData" which has a XMLPort parameter.

    Could you explain me in little more detail?

    Best Regards,
    MMV
  • Options
    einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    You can expose any ListPart page as a Web Service and it will automatically provide you with a method call ReadMultiple. Maybe you could use this to get your list of available Dimensions.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • Options
    MMVMMV Member Posts: 99
    Hi einsTeIn.NET,

    I did exactly what you said except that I wanted to insert the data in NAV so I used CreateMultiple and it worked.

    Thanks a lot.

    =D> =D> =D>

    Best Regards,
    MMV
Sign In or Register to comment.