• Resolved siddiquemahsud

    (@siddiquemahsud)


    I needed to add a file uploader in a custom form, and want to save the file in notes (annotation) entity in CRM. any example please.

    {% form entity="contact" mode="create"  %}
    <form>
        <div class="form-group">
            <label>
                First Name:
                <input class="form-control" name="firstname">
            </label>
        </div>
        <div class="form-group">
            <label>
                Last Name:
                <input class="form-control" name="lastname">
            </label>
        </div>
        <div class="form-group">
            <label>
                Upload a file:
                <input type="file" class="form-control" name="file1" >
            </label>
        </div>   
        <div class="form-group">
            <button type="submit" class="btn btn-primary">Send</button>
        </div>
    </form>
    {% endform %}
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author alexacrm

    (@alexacrm)

    Are you looking to upload file using Dataverse plugin? For Dynamics 365 we have Upload attachments in twig forms – AlexaCRM kb article

    Thread Starter siddiquemahsud

    (@siddiquemahsud)

    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

    Plugin Author alexacrm

    (@alexacrm)

    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 11 months, 3 weeks ago by alexacrm.
    Thread Starter siddiquemahsud

    (@siddiquemahsud)

    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 );
    Plugin Author alexacrm

    (@alexacrm)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Forms – How add notes/annotation’ is closed to new replies.