Monday 8 October 2018

Pass Date and Real (double) datatype from C# to AIF (Sales order)

This is a tricky thing to do. Let's say you are creating a sales order using AIF and you wanted to test it using WSDL from C#.

Everything until this point seems to be very easy, now let's say you have some custom field of type Real and you want to pass a value to that field.

Here comes the trick, for any real or date type variables we need to explicitly specify that we are passing these field values, then only these values will appear in the inbound XML file.

Now how do we do that?
Below is the code sample, as you can see there are two lines for adding MK_PurchPrice. One we will specify that this filed value is going to pass by using MK_PurchPriceSpecified = true and the second line is the actual value. i.e MK_PruchPrice = xxxx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using createSalesOrderAIF.ServiceReference1;

namespace createSalesOrderAIF
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = new AxdEntity_SalesLine()
            {
                MK_PurchPriceSpecified = true,
                MK_PurchPrice = Convert.ToDecimal(100.20),
                ItemId = "2476619",
                SalesQty = 20,
                SalesUnit = "ea",
                SalesPriceSpecified = true,
                SalesPrice = 200
               
            };

            var order = new AxdEntity_SalesTable()
            {
                CustAccount = "C5001",
                PurchOrderFormNum = "xyz",
                MK_VendAccount = "V1310",
               
                ReceiptDateRequestedSpecified = true,            
                ReceiptDateRequested = DateTime.Now.Date,
                MKTotalGSTSpecified = true,
                MKTotalGST = Convert.ToDecimal(20.10),
                MK_PurchInvoiceId = "Inv_25",
                SalesLine = new AxdEntity_SalesLine[] { line }
            };

            var orderList = new AxdEntity_SalesTable[] { order };
            var callContext = new CallContext() { Company = "ZW01" };
            var client = new SalesOrderServiceClient();

            try
            {
                client.create(callContext, orderList);
                client.Close();
            }
            catch
            {
                client.Abort();
                throw;
            }
        }
    }
}

No comments:

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...