Insert Subform data in Card page by web service

sagesage Member Posts: 29
edited 2015-01-19 in NAV Three Tier
Hi all helper,
I use NAV2013R2 and have a problem insert Subform data in Card page by web service and got this error.
:!: "The field No. of table Sales Line contains a value (1000) that cannot be found in the related table (Standard Text)." :!:
I guess because it's a field that have to validate from "Type" field and don't know how to insert it.

I attempted to insert line first and use service.Update() but the result is the same.
using WebService;

    class Program
    {
        static void Main(string[] args)
        {        
            string custNo = "10000";
            string custName = "Name - 10000";
            string itemNo = "1000";

            // Create instance of service
            SalesInv_Service salesInvoice;
            SalesInv_Service_Service service;
           
            salesInvoice = new SalesInv_Service();
            service = new SalesInv_Service_Service();
            service.UseDefaultCredentials = true;

            salesInvoice.Sell_to_Customer_No = custNo;
            salesInvoice.Sell_to_Customer_Name = custName;        

            Sales_Invoice_Line[] salesInvLine = new Sales_Invoice_Line[1];
          
            salesInvLine[0] = new Sales_Invoice_Line();
            salesInvLine[0].Type = WebService.Type.Item;
            salesInvLine[0].No = itemNo; // <------ itemNo "1000" exist in Item Master
            salesInvLine[0].Description = "xx";
            salesInvoice.SalesLines = salesInvLine;
            service.Create(ref salesInvoice);
                
            Console.ReadLine();
            
        }
    }

Any suggestion would be appreciate. Thank you.

Comments

  • denpardenpar Member Posts: 80
    I'm not a C# expert, but did you try....

    salesInvLine[0].Type = 2;
    If your work becomes a passion...
    www.pardaan.com
  • sagesage Member Posts: 29
    Hi denpar,

    I got the compile error because wrong data type. It's not a Integer.
  • denpardenpar Member Posts: 80
    Type is an option string...

    Options
    Blank (0) -> this means standard text
    G/L Account (1)
    Item (2)
    Resource (3)
    Fixed Asset (4)
    Charge (Item) (5)

    The error message implicates that the field 'Type' is blank. So when validating the field 'No' with value 1000, NAV is looking for a standard text with code 1000 instead of an item 1000....

    In C/AL you can change the field type with the following code:

    "sales invoice line".type := "sales invoice line".type::Item

    or

    "sales invoice line".type := 2;
    If your work becomes a passion...
    www.pardaan.com
  • sagesage Member Posts: 29
    Hi again Denpar,

    Error is from C# not from C/AL.

    I have no problem insert option string in C/AL but this is outside the C/SIDE and I don't know how to insert field which is an option.

    I already tried
    salesInvLine[0].Type = WebService.Type.Item;
    This has no error but when I look in database it inserted blank.

    and tried
    salesInvLine[0].Type = 2;
    It error when compile because wrong data type as I said.

    :(:(:(
  • denpardenpar Member Posts: 80
    As said I'm not a C# export... So I'm afraid I can't help you further :(

    But I'm 100% sure the error you receive is a NAV error caused by validating the field 'No' with value 1000 while the field 'Type' is blank!
    If your work becomes a passion...
    www.pardaan.com
  • sagesage Member Posts: 29
    Thanks Denpar.
    Although error still can't resolve, I'm very appreciated your help :)
  • sagesage Member Posts: 29
    AHA !!
    Maybe I went to the wrong step. Now I can insert optionString by follow this instruction. :D

    http://blogs.msdn.com/b/freddyk/archive ... d-rtm.aspx
Sign In or Register to comment.