Answer the question
In order to leave comments, you need to log in
How to make a file substitution on the OnBeforeCrmDealUpdate event?
Please tell me, I want to replace the file in the transaction on the OnBeforeCrmDealUpdate event.
the code:
public static function createDealBasedOnFiles(&$fields)
{
$deal = \CCrmDeal::GetList([], array('ID' => $fields['ID']))->Fetch();
if ($deal['UF_CONTRACT_REGISTER_DOCUMENT'][0] !== $fields['UF_CONTRACT_REGISTER_DOCUMENT'][0]) {
$resPdf = DealSubscriber::createPdf($fields['UF_CONTRACT_REGISTER_DOCUMENT'][0]);
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']), 'https') === false ? 'http' : 'https';
$fields['UF_CONTRACT_REGISTER_DOCUMENT'][] = [
'fileData' => [
preg_replace('#.*/#', '', $resPdf['path']),
base64_encode(file_get_contents($protocol . '://' . $_SERVER["SERVER_NAME"] . $resPdf['path']))
]
];
}
}
Answer the question
In order to leave comments, you need to log in
You have already answered correctly in your question: How to attach a file to a transaction in a multiple field of the File type?
1) When working with a boxed API, using the cloud API is not allowed.
Instead of construct:
$fields['UF_CONTRACT_REGISTER_DOCUMENT'][] = [
'fileData' => [
preg_replace('#.*/#', '', $resPdf['path']),
base64_encode(file_get_contents($protocol . '://' . $_SERVER["SERVER_NAME"] . $resPdf['path']))
]
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question