web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Custom File Upload Control

(0) ShareShare
ReportReport
Posted on by 7,316

Hi,

I am building a custom file upload control using html web resource in a custom entity(FileUpload).

User will be uploading data in .csv format. I want to build something that process this data and update 'incident' entity as and when user uploads files.

Can someone please provide a sample example for me. I've been searching around for a startup to proceed but couldn't find one. Thanks for any help in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi meenoo,

    You want to use an input control, of type file. You'll be able to get the file from the .files  property. Here's the specs on how you can interact with that control: www.w3schools.com/.../dom_obj_fileupload.asp .

    You can process the file in javascript, but I'm a plugin guy so I would upload it to CRM as a note and process the file as a plugin (with the added benefit of rolling back if there's an unexpected error with the file).

    If this helps I'd appreciate if you'd mark this as a Verified answer.

    Thanks,

     Aiden

  • meenoo Profile Picture
    7,316 on at

    Thanks Aiden, that pretty much explains an outline of how to do it.

    I think my requirement is to run this import process at a certain time every day.. like a scheduled import.

    I gathered couple of ways to do it but have some questions hoping you can answer them:

    1. Create a recurrent workflow that will be triggered everyday at 12:00 AM.

    2.  Create a custom workflow activity.

    3. Use this as a step in recurrent workflow.

    Questions: Where do I store the uploaded file until the workflow gets triggered to process the data?

    Is this approach even correct?

    Another way:

    Use SSIS to transform the data and import into CRM entities using a schedule job.

    Again where do I store the file uploaded??

    Does this approach make sense at all?

    Please guide me through this.

    Thanks again!

  • Verified answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi!

    There's a lot to tackle so I'll try my best.

    -- Storing the file --

    If you want people to have files in CRM to be processed for this case, I'd set up a new queue called "Files to Process" or something. When you have a file to process, create a Task and attach your file as a note, then assign it to the queue. When your code is processing files, it'll look for Open tasks assigned to that queue and close (or delete) them after its been processed. This will let you track the files to import in CRM, as well as the ones that have already been completed (in case you need to reference them in the future).

    -- Scheduling --

    Having a recurring workflow seems like its been the most common feature request for years. There are a few hackey ways to do it, and a couple that are more reliable.

    Option 1 - Windows service

    If you're using CRM on premise and have access to the server, you can create a windows service to run and either trigger the workflow at the right time, or process the file directly. This is very reliable because the service will be running as long as your service is up - you won't need to worry about a single workflow failing and having cascading issues. I use this technique all the time and it's my preference.

    Option 2 - SSIS

    If you're storing the file to process in CRM then this probably isn't the way to go. It would make sense if you had it on a server or database, but not already in CRM.

    Option 3 - Workflows initiating workflows

    This is a hackey way to have one workflow kick off another that runs at a later time. I don't like this because one workflow could fail and that would break the whole process.

    -- Processing --

    This depends partly on how long the file will take to process. In workflows and in plugins, there's a two minute timeout and anything longer than that will fail. If the file will take longer than you need to do the actual processing outside of CRM (directly in the windows service, most likely).

    If the file processing will be quick,  you can write it as a custom workflow assembly. Here's a good write-up on creating a custom workflow step. msdn.microsoft.com/.../gg334455.aspx

    Wherever you code actually runs, processing it will be the same. You'll find annotations and the documentbody field will have the content of the uploaded document as the string representation of the bytes of the file. To convert it to a byte[] for proper processing, you'd convert it like this:

    byte[] fileContent = Convert.FromBase64String(theDocumentBodyField);

    I think that covers everything. If I missed anything or I need to clarify I'd be happy to. As always, I'd appreciate if you could mark any helpful answers as Verified.

    Thanks,

     Aiden

  • meenoo Profile Picture
    7,316 on at

    That's very informative. Thanks Aiden.

  • Aiden Kaskela Profile Picture
    19,696 on at

    I'm happy to help, let me know if you have any questions or hit a roadblock.

    Good luck!

  • crmprogrammer2013 Profile Picture
    2,665 on at

    Nice concept. Thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans