crm.invoice.update
Scope: catalog Permissions to execute: for all
crm.invoice.update(id, fields)
Updates the specified (existing) invoice.
Parameters
Parameter | Description |
---|---|
id | Updated invoice ID. |
fields | Set of fields - is an array (“updated field"=>”value”[, ...]), containing field values of the crm.invoice.fields.
Note: to find out the required field format, execute the method crm.invoice.fields to view the retrieved field format.
|
Example
// Add or update an item in an invoice var id = prompt("Enter ID"); BX24.callMethod('crm.invoice.get', {"ID": id}, addProduct); function addProduct(result) { if(result.error()) console.error(result.error()); else { var fields = clone(result.data()); var n = fields['PRODUCT_ROWS'].length; var productUpdated = false; // update the created-on date fields["DATE_BILL"] = "date2str(current)"; // update the "Invoice notes (appears on invoice)" field fields["USER_DESCRIPTION"] = "Invoice notes (updated)."; // If the invoice includes an item ID=703, update the item fields. // Otherwise, create and add a new product item. // We safely assume the price includes taxes because // we can tell if it's not by the catalog's tax-included flag. for (var i in fields['PRODUCT_ROWS']) { if (fields['PRODUCT_ROWS'][i]["PRODUCT_ID"] == 703) { var rowId = fields['PRODUCT_ROWS'][i]["ID"] fields['PRODUCT_ROWS'][i] = { "ID": rowId, "PRODUCT_ID": 703, "QUANTITY": 4, "PRICE": 779.60 }; productUpdated = true; break; } } if (!productUpdated && n > 0) { fields['PRODUCT_ROWS'][n] = { "ID": 0, "PRODUCT_ID": 703, "QUANTITY": 5, "PRICE": 779.60 }; } BX24.callMethod('crm.invoice.update', {"ID": id, "FIELDS": fields}, function(result) { if(result.error()) console.error(result.error()); else { console.info("Invoice ID=" + result.data() + "has been updated."); } } ); } } function clone(src) { var dst; if (src instanceof Object) { dst = {}; for (var i in src) { if (src[i] instanceof Object) dst[i] = clone(src[i]); else dst[i] = src[i]; } } else dst = src; return dst; }
© «Bitrix24», 2001-2024