Are you looking to upload file using Dataverse plugin? For Dynamics 365 we have Upload attachments in twig forms – AlexaCRM kb article
Hi Alexa team – Yes we currently switched to Dataverse plugin. Can you please give me some example or doc to upload file in Dataverse plugin? Thanks in advance
We do not have go to sample yet for the custom file upload in Dataverse plugin. The approach will be very similar to the sample Upload attachments in twig forms – AlexaCRM except the action to intercept will be integration-cds/forms/submit-success – see Hooks Reference « AlexaCRM for parameters description.
You can also take a look at the CRM form implementation (see function respond in SubmitForm.php) as CRM forms do support file upload.
Once we have the sample code we will share it as a kb article.
-
This reply was modified 2 years, 5 months ago by
alexacrm.
I attempted to replace the function for Dataverse Integration plugin as outlined below, but unfortunately, it doesn’t seem to be working.
I believe I may have replaced the following lines incorrectly, possibly due to my limited experience with PHP code 🙂 If you have any guidance or suggestions, I would greatly appreciate your assistance.
D365 plugin:
$files = ACRM()->request->files;
$fields = ACRM()->request->request;
I replaced them like below, but not sure if it’s correct
$files = $_FILES;
$fields = $_POST;
add_action( 'integration-cds/forms/submit-success', function(
\AlexaCRM\Nextgen\Forms\CustomFormModel $model,
\AlexaCRM\Xrm\Entity $record ) {
$files = $_FILES;
$fields = $_POST;
$client = ConnectionService::instance()->getClient();
if ( $fields->get( '__formid' ) !== '1234-6789' ) {
return;
}
$subjectLines = [
'file-1' => 'File name 11',
'file-2' => 'File name 22'
];
foreach ( [ 'file-1', 'file-2' ] as $field ) {
$file = $files->get( $field );
if ( !( $file instanceof \Symfony\Component\HttpFoundation\File\UploadedFile ) ) {
continue;
}
$annotation = new Entity( 'annotation' );
$annotation->objectid = $record;
$annotation->subject = $subjectLines[$field];
$annotation->documentbody = base64_encode( file_get_contents( $file->getRealPath() ) );
$annotation->mimetype = $file->getMimeType();
$annotation->filename = $file->getClientOriginalName();
$client->create( $annotation );
}
}, 10, 2 );
Until we create a sample, I suggest checking out CrmForm implementation from the premium. That’s what we’re going to base our sample on.