Hi,
I have been struggling with an issue, and am also somewhat an amateur developer as well.
I have a php function, which creates a new sales line to an existing blanket sales order. I do this via both update and update_multiple methods.
I can create new sales lines, and my code works all the time. If i add to my code ability to set the "Unit_Price", i get an error:
The Sales Line already exists. Identification fields and values: Document Type='Blanket Order',Document No.='3060',Line No.='10000'
If i write some code that first creates the blanket order, and then updates it with sales lines, i can make it work. The code for update is more or less the same.
The sales line as far as i can see, is always new, even if the blanket order itself is new or old. Or is this where i am wrong?
The only solution i see this far, is to re-read the order after i have put everything but the unit_price, and then set the price only. I am struggling on how to identify the line to edit, since there is no identical key, except the "key". What i am trying to say, how do i know which key i want to make an update to, after i have created a new line. NAV does not say "you just created xxx with key xxx. I have to read the order and somewhat guess which line i just created.
Anywho, here is my code:
Code:
$service = new NTLMSoapClient($pageURL);
$blanketorder = new stdClass();
$sq = new stdClass();
$update = new stdClass();
// Read order to update
foreach ($varelinjeny as $order1) {
$blanketorder = array('No' => $order1[onr]);
$result = $service->Read($blanketorder);
$blanket = $result->OrderCard;
$key = $result->OrderCard->Key;
//Set the key to use for update-message later on
$sq->Key = $key;
$ii = 0;
$i = -1;
foreach ($varelinjeny as $ordre1) {
$ii++;
unset ($salesLine);
$salesLine = new stdClass();
// $salesLine->Key = $ii;; //this only works if i create the order first
$vare = explode("|",$ordre1[varenr]);
$i++;
$salesLine->Type = 'Item';
$salesLine->No = $vare[0];
$salesLine->Unit_Price = "123"; //comment out this, and code is ok
if ($ordre1[otf] == 'on') {
$salesLine->One_time_fee = 'true';
} else {
$salesLine->One_time_fee = '';
}
$salesLine->Antall_opprinnelig_bestil = $ordre1[antall];
//some custom fields
if (!empty($ordre1[nocat])) {
$salesLine->Username = $ordre1[nocat];
}
if (!empty($ordre1[linespeed])) {
$salesLine->Line_Speed = $ordre1[linespeed];
}
if (!empty($ordre1[binding])) {
$salesLine->Subscription_Time = $ordre1[binding];
}
if (!empty($ordre1[smbnr])) {
$salesLine->Communication_Number = $ordre1[smbnr];
}
// Add SalesLineList to SalesQuote
$sq->SalesLines[$i] = $salesLine;
}
}
$update->OrderCard = $sq;
$result = $service->Update($update);
Thanks
--
Kim