Quantcast
Channel: Microsoft Dynamics NAV
Viewing all articles
Browse latest Browse all 64865

Forum Post: RE: Unable to set Unit_Price on sales line via webservice

$
0
0
Hi, Solved it, sort of. Feeling that i have to do a lot of roundtrips with this stuff, but it works... What i ended up doing is this, and i think it is what Ishwar meant: I read the order to get the keys to use for update I run a update, creating a new salesline. Here i set all that NAV accepts in this update, omitting Unit_Price. I read the result of this, and loops trough all keys to save them in an array. At the same loop i also strip the keys so that i get the last part of it, split at "9;" . I the find the highest number of this key-part, and that has to be the last record. Then i use the key belonging to the latest record, to do a new update, setting the price. My code for this probably bloated and considered "bad practice" or something like that, but as i said, i am an amateur :P Regards, and thanks! -- Kim $service = new NTLMSoapClient($pageURL); //Set some vars $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; $sq->Key = $key; //$sq2->Key = $key; $ii = 0; $i = -1; foreach ($varelinjeny as $ordre1) { $ii++; unset ($salesLine); $salesLine = new stdClass(); $salesLine->Type = 'Item'; $vare = explode("|",$ordre1[varenr]); $salesLine->No = $vare[0]; //$salesLine->Unit_Price = '123'; if ($ordre1[otf] == 'on') { $salesLine->One_time_fee = 'true'; } else { $salesLine->One_time_fee = ''; } $salesLine->Antall_opprinnelig_bestil = $ordre1[antall]; 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];//date('Y-m-d', strtotime('+1 years')); } if (!empty($ordre1[smbnr])) { $salesLine->Communication_Number = $ordre1[smbnr]; } $sq->SalesLines->Blanket_Sales_Order_Line = $salesLine; $update->OrderCard = $sq; $result = $service->Update($update); foreach ($result->OrderCard->SalesLines->Blanket_Sales_Order_Line as $finditem){ $linekey[] = $finditem->Key; //strip keys to the last part only split at "9;" $keytoedit[] = substr($finditem->Key, strpos($finditem->Key, "9;")+ 2); } //find the highest value of key-part $value = max($keytoedit); //find the full key for this part foreach ($linekey as $lkey){ if (strpos($lkey,"9;".$value ) !== false) { $ekey = $lkey; echo "Key to edit: ".$ekey; } } echo "Highest key-part:".$value; $key2 = $result->OrderCard->Key; $sq->Key = $key2; //assigning here the "difficult" stuff $salesLine2->Key = $ekey; $salesLine2->Unit_Price = "123"; $sq->SalesLines->Blanket_Sales_Order_Line = $salesLine2; $update->OrderCard = $sq; $result = $service->Update($update); } } echo "We got no errors in placing the order! To make sure; doublecheck by clicking here: $mamutid "; } catch (Exception $e) { echo 'Crap, we hit an error: ' . $e->getMessage() . ' '; }

Viewing all articles
Browse latest Browse all 64865

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>