API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

Problems with OrderLine_CreateFromDataArray

0
Hello experts.

I am having very many trouble using the OrderLine_CreateFromDataArray function.

I tried to change very many things, but here is a code snip, how i read it should be?


//$orderHandle is defined and is correct - used earlier in the program

    $orderlines = array();
    
    for($i = 0; $i  count($productData); $i++)
    {
        $orderlines = array(
                            Number=$productData$ivarenr,
                            ProductHandle=array(Number=$productData$ivarenr),
                            OrderHandle=$orderHandle,
                            Description=$productData$inavn,
                            UnitNetPrice=$productData$isalg,
                            Quantity=$productData$iantal,
                            DiscountAsPercent=0,
                            UnitCostPrice=0,
                            TotalMargin=0,
                            MarginAsPercent=0
                            );
    }
    $client-OrderLine_CreateFromDataArray(array(dataArray=$orderlines));


it tells me that The 'id' attribute is not declared. {id=773006397}

I'v tried change many settings,

But, if there is only one item in $productData (my orderlines), then it is creating the orderline correct, but when multiple lines is entered, it throws out an error.

When i try to read the error, i tried setting $orderlines[Id] = 0; to see what happends - and then the SoapServer Parser accepts it - but of cause with no data. - i just can figure out, why? it is like the server is'nt handling the data, as it is supposed to (WSDL)?

Hope anyone responds, maybe you have experimented the same error
created Jan 18, 2010 by ksvendsen
20% Accept Rate
Q 6 A 12 C 1

3 Answers

0
I've had exactly the same problem using CurrentInvoiceLine_CreateFromDataArray.

The problem is because the references (or aliases) present within PHP's inner workings is reflected in the resulting xml sent via your SoapClient call.

So if your array contains more than one array you get the following problem:


?xml version=10 encoding=UTF-8?             
SOAP-ENVEnvelope xmlnsSOAP-ENV=http//schemasxmlsoaporg/soap/envelope/ xmlnsns1=http//e-conomiccom xmlnsxsi=http//wwww3org/2001/XMLSchema-instance
  SOAP-ENVBody
    ns1CurrentInvoiceLine_CreateFromDataArray
      ns1dataArray
        ns1CurrentInvoiceLineData
          ns1Handle
            ns1Id399/ns1Id
            ns1Number0/ns1Number
          /ns1Handle
          ns1Id399/ns1Id
          ns1Number0/ns1Number
          ns1InvoiceHandle id=ref1
            ns1Id399/ns1Id
          /ns1InvoiceHandle
          ns1DescriptionSeagate 250GB HD - 5400RPM/ns1Description
          ns1DeliveryDate xsinil=true/
          ns1UnitHandle
            ns1Number1/ns1Number
          /ns1UnitHandle
          ns1ProductHandle
            ns1Number155/ns1Number
          /ns1ProductHandle
          ns1Quantity10000/ns1Quantity
          ns1UnitNetPrice990000/ns1UnitNetPrice
          ns1DiscountAsPercent0/ns1DiscountAsPercent
          ns1UnitCostPrice00000/ns1UnitCostPrice
          ns1TotalNetAmount xsinil=true/
          ns1TotalMargin990000/ns1TotalMargin
          ns1MarginAsPercent10000/ns1MarginAsPercent
        /ns1CurrentInvoiceLineData

    ns1CurrentInvoiceLineData
          ns1Handle
            ns1Id399/ns1Id
            ns1Number1/ns1Number
          /ns1Handle
          ns1Id399/ns1Id
          ns1Number1/ns1Number
          boldns1InvoiceHandle href=#ref1//bold
          ns1DescriptionSeagate 500GB HD - 5400RPM/ns1Description
          ns1DeliveryDate xsinil=true/
          ns1UnitHandle
            ns1Number1/ns1Number
          /ns1UnitHandle
          ns1ProductHandle
            ns1Number154/ns1Number
          /ns1ProductHandle
          ns1Quantity10000/ns1Quantity
          ns1UnitNetPrice2990000/ns1UnitNetPrice
          ns1DiscountAsPercent0/ns1DiscountAsPercent
          ns1UnitCostPrice00000/ns1UnitCostPrice
          ns1TotalNetAmount xsinil=true/
          ns1TotalMargin2990000/ns1TotalMargin
          ns1MarginAsPercent10000/ns1MarginAsPercent
        /ns1CurrentInvoiceLineData
      /ns1dataArray
    /ns1CurrentInvoiceLine_CreateFromDataArray
  /SOAP-ENVBody
/SOAP-ENVEnvelope


The second invoice line is only a href= to the first: ns1InvoiceHandle href=#ref1/

Its perfectly valid xml, but its not accepted by the economic webservice.

Solution:


    public function createInvoiceLines($invoiceHandle) {
            $line = new stdClass();
            $invoiceH = new stdClass();
            $invoiceH-Id = $invoiceHandle-Id;

            $line-InvoiceHandle = $invoiceH;
            $line-Number = $x; // line no
            


Instead of this:


    public function createInvoiceLines($invoiceHandle) {

            $line = new stdClass();
            $line-InvoiceHandle = $invoiceHandle
            $line-Number = $x; // line no
            


where $invoiceHandle is already an object containing the Id of the Invoice just created.

 So - redefine your objects from scratch, adding preexisting ones will generate references in your xml !

Further reference is here: http//blogferyneu/2009/01/warning-object-references-affect-xml-serialization/comment-page-1/

Hope it helps you solve the problem.

-stefan
answered Feb 16, 2010 by stefans
0
I get that error message to, but i'm using  Product_UpdateFromDataArray
I tried the soultion, but still get the error, so i must be missing something.
Here is my code:

function CreateProduct($client,$artNr,$name,$groupIndex,$sellPrice,$ProductGroupHandles) {
    $ProductGroup = $ProductGroupHandles$groupIndex;
    $productHandle = $client-Product_FindByNumber(array(
                'number' = $artNr))-Product_FindByNumberResult;
//Solution from forum
        $productH = new stdClass();
        $productH-Id = $productHandle-Id;
    $product = array(productHandle = $productH,
//Solution from forum
    //$product = array(productHandle = $productHandle,
    Number = $artNr,
    ProductGroupHandle =$ProductGroup,
    Name = $name,
    SalesPrice = $sellPrice,
    CostPrice = 0,
    RecommendedPrice = 0,
    Volume = 0,
    IsAccessible = 2);
    return $product;
}


            $product = CreateProduct($client,$array0,$Name,$groupIndex,$price,$ProductGroupHandles);
            $ProductsArray = $product;


    $client-Product_UpdateFromDataArray(array(
        'dataArray' = $ProductsArray,
    ));
answered Nov 11, 2010 by Madman
0
I changed productHandle to Handle, beacuse that's the correct syntax.
But the problem remains.
I removed the Id code and tried

             $client-Product_UpdateFromData(array(
             'data' = $product));

And it worked with no problem.
Also printed the $product and it's returns as it should.
I also printed with the Id code, and it sais Id =. So there is no Id in the ProductHandle, so my question is. Where do I get the Id of an product?
answered Nov 13, 2010 by Madman
Visma e-conomic A/S
...