Can codeunit accept Dataset/Datatable as parameter ?

casanovacasanova Member Posts: 194
edited 2013-02-04 in NAV Three Tier
hi all
i create program outside nav
and then it will stored it in dataset
what i want is send this dataset as parameter to codeunit
and then codeunit will proses this dataset to do the process
any clue or sample?
thanks

Comments

  • deV.chdeV.ch Member Posts: 543
    you need to pass the data in text format (string)

    i would suggest to use binary serialization to serialize your datatable and then use Base64 conversion to receive a string, this one you can pass to the webservice (i guess you use webservices to connect to nav).
     public static string Serialize(DataSet ds) {
            Stream stream = null;
            BinaryFormatter serializer = new BinaryFormatter();
            serializer.Serialize(stream, ds);
            return Convert.ToBase64String(stream.ToArray());
        }
    

    In Nav you can then deserialize the data back to a instance of a DataSet

    But since you need to process the data anyway i would suggest to find out if passing an xml data strucutre is more suitable for your task. Becaus if you for example need to import the values of the your DataSet then with an xml strucutre you could use a xmlport and would need very little code to do your task. If you need to process a DataSet in NAV I guess you need lots of code to achieve the same.

    So the question is what do you want to do with your DataSet once you have it in NAV
  • casanovacasanova Member Posts: 194
    yes correct i'm using webservice
    so... from my program it will store in dataset or datatable
    after that , i will send this dataset and datatable as a parameter to codeunit
    my codeunit will be published as webservice
    is it can be done?
  • deV.chdeV.ch Member Posts: 543
    If you read my post carefully you will find the answer...

    No you cannot pass a dataset directly, as i said you need to serialize your data.
  • casanovacasanova Member Posts: 194
    i thought use string before...
    but how about if my file is more than 1024 character
    i thought text in NAV variable max is 1024 character
  • deV.chdeV.ch Member Posts: 543
    Use BigText as datatype, it has no length limit.
  • casanovacasanova Member Posts: 194
    how to use this big text anyway
    lets say i have xml file from outside
    C:\Sample.xml

    and then i want to import this xml file
    XMLFile := 'C:\Sample.xml'
    TestFile.Read(XMLFile);
    ImportData(TestFile);
    

    failed
Sign In or Register to comment.