S
S
sanekmihailow2020-04-17 17:44:06
1C-Bitrix
sanekmihailow, 2020-04-17 17:44:06

How to pull a custom field from an account into a deal?

It is necessary in the deal business process , through the php code , to get the value of the custom field from the account associated with the deal . Then write this value in the deal field? Actually, how can I get the account id , and how can I then pull out the value? This is necessary because there is a partial payment, and through the value of the payment received, you need to calculate the salary.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2020-04-18
@sanekmihailow

Use the list method GetList() .

$arOrder = ["ID" => "DESC"]; // сортировка
$arFilter = ["UF_DEAL_ID" => $dealId]; // фильтрация по ID сделки
$arSelect = ["ID", "UF_DEAL_ID"]; // какие поля выбрать

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

while($invoice = $invoices->Fetch()) {
    // ваш код
}

The problem can arise if the transaction has several accounts (in fact, this is why the cycle is used), so additional filtering parameters will be required.
You can also use crm.invoice.list rest method . But for this, you will need to additionally generate an incoming webhook and use HttpClient to call the method
, in which case the code will be something 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) {
    // ваш код
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question