<div dir="ltr">Hi Chris,<br><br>While saving the details of Invoice line items, we are removing the
existing information of line items and expecting the updated line items
information from $_REQUEST.<br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><b><span style="font-family:verdana,sans-serif"><span style="color:rgb(153,153,153)"><span style="background-color:rgb(255,255,255)">regards,</span></span><br>Satish.Dvnk</span></b><br></div></div></div>
<br><div class="gmail_quote">On Wed, Dec 3, 2014 at 9:54 AM, Hamono, Chris (DPC) <span dir="ltr"><<a href="mailto:Chris.Hamono@sa.gov.au" target="_blank">Chris.Hamono@sa.gov.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<font face="Calibri, sans-serif">
<div>I am programmatically updating a couple of fields in an invoice. When I save the invoice the changes are correctly recorded but it loses the attached product.</div>
<div> </div>
<div>I am using the following code what am I doing wrong?</div>
<div> </div>
<div> </div>
<div><font face="Courier New, monospace"> // create the model from the record id</font></div>
<div><font face="Courier New, monospace"> $invoiceModel = Vtiger_Record_Model::getInstanceById($invoiceid, "Invoice");</font></div>
<div><font face="Courier New, monospace"> </font></div>
<div><font face="Courier New, monospace"> if ($invoiceModel) {</font></div>
<div><font face="Courier New, monospace"> // set the fields as supplied</font></div>
<div><font face="Courier New, monospace"> foreach ($fields as $key=>$value){</font></div>
<div><font face="Courier New, monospace"> $invoiceModel->set($key, $value);</font></div>
<div><font face="Courier New, monospace"> }</font></div>
<div><font face="Courier New, monospace"> </font></div>
<div><font face="Courier New, monospace"> // set mode to edit</font></div>
<div><font face="Courier New, monospace"> $invoiceModel->set('mode', 'edit');</font></div>
<div><font face="Courier New, monospace"> </font></div>
<div><font face="Courier New, monospace"> // save</font></div>
<div><font face="Courier New, monospace"> $invoiceModel->save();</font></div>
<div><font face="Courier New, monospace"> </font></div>
<div><font face="Courier New, monospace"> return $invoiceModel->getData();</font></div>
<div><font face="Courier New, monospace"> }</font></div>
<div> </div>
<div>If I var dump the array returned by getData() it correctly shows the product and the changes.</div>
<div> </div>
<div>e.g.</div>
<div> </div>
<div><font size="3" face="Courier New, monospace">['invoicestatus'] =>'Paid' <= status changed</font></div>
<div><font size="3" face="Courier New, monospace">['cf_738'] =>'BZ-0025028687' <= custom field being updated</font></div>
<div><font size="3" face="Courier New, monospace">['invoice_no'] =>'INV405'</font></div>
<div><font size="3" face="Courier New, monospace">['productid'] =>2175</font></div>
<div><font size="3" face="Courier New, monospace">['quantity'] =>1.000</font></div>
<div><font size="3" face="Courier New, monospace">['listprice'] =>605.00000000<font face="Calibri, sans-serif"> </font></font></div>
<div> </div>
<div> </div>
<div>If I then go to the invoice detail page. The changes I have made are correctly saved (in the above I am setting the status field to ‘Paid’ and setting a custom field) but the invoice no longer has any products attached to it.</div><span class="HOEnZb"><font color="#888888">
<div> </div>
<div> </div>
<div>Chris</div>
<div> </div>
<div> </div>
</font></span></font>
</div>
<br>_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br></blockquote></div><br></div>