How to pull a custom field from accounts in the transaction?

Need in a business process transactions using php code to get the value of custom fields from a linked transaction account. Then record that value in the transaction? Actually how can I get invoice id, and then how to pull out value? Need this because there is a partial payment, and using the value of the payment received to do the salary calculation.
April 19th 20 at 12:34
1 answer
April 19th 20 at 12:36
Use the payroll method GetList().

$arOrder = ["ID" => "DESC"]; // sorting
$arFilter = ["UF_DEAL_ID" => $dealId]; // filter by ID of the transaction
$arSelect = ["ID", "UF_DEAL_ID"]; // what fields to choose

$invoices = CCrmInvoice::GetList($arOrder, $arFilter, false, false, $arSelect);

while($invoice = $invoices->Fetch()) {
 // your code
}


This problem can occur if the transaction multiple accounts (actually, so cycle is used), so you will need additional filtering options.

You can also use the rest method crm.invoice.list. But you will need to additionally generate incoming webhook and use HttpClient to invoke a method

in this case, the code will be like this:

use Bitrix\Main\Web\HttpClient;
use Bitrix\Main\Web\Json

$client = new HttpClient;

$webhook = "https://webhook_url/crm.invoice.list";
$params = [
 "filter" => $arFilter,
 "order" => $arOrder
];

$request = $client->post($webhook, Json::encode($params));
$result = Json::decode($request);

foreach($result["result"] as $res) {
 // your code
}

Find more questions by tags Bitrix241C-Bitrix