Reputation: 69
Let's say I've the web service for NAV dynamics
inside the web services there are some business objects which one of them is enum type
public Type Type {
get {
return this.typeField;
}
set {
this.typeField = value;
}
}
and has the value for the objects below, which contains in the web services too
public enum Type{
/// <remarks/>
_blank_,
/// <remarks/>
G_L_Account,
/// <remarks/>
Item,
/// <remarks/>
Fixed_Asset,
/// <remarks/>
Charge_Item,
}
the case is when doing this method below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using NAVDomain;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using LocalDomain;
using NAVFacade.GoodReturnNAVService;
public bool SaveData(PurchCrdMemoNav objHd, List<Purch_Cr_Memo_Line> objDt)
{
PurchCrdMemoNav_Service service = new PurchCrdMemoNav_Service();
NetworkCredential cred = new NetworkCredential();
try
{
cred.UserName = ConfigurationManager.AppSettings["NAVUser3"];
cred.Password = ConfigurationManager.AppSettings["NAVPassword3"];
cred.Domain = ConfigurationManager.AppSettings["NAVDataSource3"];
service.Credentials = cred;
PurchCrdMemoNav DataSave = new PurchCrdMemoNav();
DataSave.No = objHd.No;
service.Create(ref DataSave);
var purch = service.Read(objHd.No);
DataSave.Buy_from_Vendor_No = objHd.Buy_from_Vendor_No;
DataSave.Buy_from_Vendor_Name = objHd.Buy_from_Vendor_Name;
DataSave.Applies_to_Doc_Type = objHd.Applies_to_Doc_Type;
DataSave.Applies_to_Doc_No = objHd.Applies_to_Doc_No;
DataSave.Location_Code = objHd.Location_Code;
DataSave.Posting_Date = objHd.Posting_Date;
DataSave.Key = purch.Key;
service.Update(ref DataSave);
DataSave.PurchLines = new Purch_Cr_Memo_Line[objHd.PurchLines.Count()];
for (int i = 0; i < objHd.PurchLines.Count(); i++)
{
DataSave.PurchLines[i] = new Purch_Cr_Memo_Line();
DataSave.PurchLines[i].Document_Type = Document_Type.Credit_Memo;
DataSave.PurchLines[i].Document_No = objHd.No;
DataSave.PurchLines[i].Type = NAVFacade.GoodReturnNAVService.Type.Item;
DataSave.PurchLines[i].No = objHd.PurchLines[i].No;
DataSave.PurchLines[i].Description = objHd.PurchLines[i].Description;
DataSave.PurchLines[i].Unit_of_Measure = objHd.PurchLines[i].Unit_of_Measure;
DataSave.PurchLines[i].Quantity = objHd.PurchLines[i].Quantity;
}
service.Update(ref DataSave);
return true;
}
catch (Exception err)
{
MsgCode = 99;
MsgDesc = err.Message;
return false;
}
}
the problem is when executing the service.Update(ref DataSave)
after the loop
its catching an error which said
The field No. of table Purchase Line contains a value (C125) that cannot be found in the related table (Standard Text).
because in NAV, when saving this one transaction, it needs to check it's item type each that recorded in this object below
DataSave.PurchLines[i].Type = NAVFacade.GoodReturnNAVService.Type.Item;
I've done the debugging and inside the DataSave.PurchLines[i].Type, there's the data that has the value as Item
but when i check the database, the data aint saved
in NAV the object read as option, in SQL the object read as integer
please help,
I'm kind of stuck here since anything on my code is working except this method
sincerely,
just another mediocore junior developer
Upvotes: 2
Views: 945
Reputation: 262
Maybe your value isn't sent correctly, check if there is attribute "YourField"_Specified and set it to true...
EX: ...
currWorkOrder.Order_Type = Order_Type.AKC; //(Order_Type)2;
currWorkOrder.Order_TypeSpecified = true;
... When i don't set
Order_TypeSpecified = true;
plugin sends default value, so 0...
Upvotes: 1
Reputation: 705
yes, the Type field in NAV is an Option field but it's stored as Integer therefore you need to give it a numeric value. Check with a NAV Developer of the actual database but the default values are: " ,G/L Account,Item,,Fixed Asset,Charge (Item)" - it starts from 0 so if you want Item you'll need 2
I hope it helps!
Cheers
Upvotes: 0