locked
CSV File Output for c# plugin RRS feed

  • Question

  • Hi

    I'm currently developing a plug in to work with CRM using C# and using a class library in visual studio 2013

    The plugin will be outputting CSV files to use with a different piece of software.

    The files will be created when the user creates a new customer in CRM for example

    My question is how do I output different CSV files in the same location folder without them overriding each other

    A way of giving the files a name would be ideal, but so far all I've been able to find is writing a file path in the actual code which would mean all CSV files being stored under the same name which would mean them being overridden

    Thanks 

    Monday, June 2, 2014 7:59 AM

Answers

All replies

  • You can use current time with seconds as name  OR

    you can also concatenate user name or customer name with current time to make file name.


    Regards Faisal

    Monday, June 2, 2014 8:38 AM
  • Hi Faisal

    Thanks for the quick reply

    Im not to experienced on file paths sort of thing, only ever given them a default path

    So as im currently in testing mode the file path im using is;

    @"C:\Development\Test\TestFile.csv"

    Would I have to create a string that gets the current time and add that onto the file path like this;

    @"C:\Development\Test\" + timeString + ".csv"

    timeString being the string created to hold the current time

    Or is there some sort of other way?

    Thanks, Shaun

    Monday, June 2, 2014 8:52 AM
  • Hi Shaun,

    You could also use the Contact GUID as a suffix to the CSV file that you generate. Doing that will ensure that excel files are NEVER duplicate. For that the path would be something like follows:

    @"C:\Development\ExelFiles\" + ContactName + "_" + ContactGuid + ".csv"

    "ContactName" being the name of the Contact and "ContactGuid" being the Contact Guid. You can get both of these in the Plugin that you register against Contact in Dynamics CRM.


    Admin QuikView Solution for CRM 2013

    Monday, June 2, 2014 8:59 AM
  • Dynamotion logic will work if you store one file for one contact. However if you want to store multiple files for a contact than do this:-

    @"C:\Development\Test\" + ContactName + "_" + DateTime.Now.ToString()+ ".csv"

    You may use contact ID also


    Regards Faisal

    Monday, June 2, 2014 9:08 AM
  • Thanks both for the replies

    Will let you know how it goes

    Thanks, Shaun

    Monday, June 2, 2014 9:14 AM
  • Hi guys, worked a treat thanks for the help

    I do have another question, don't know if this is the right place to ask

    But basically on my plug in I want a message box to appear if a certain criteria is met. 

    I've looked and looked online and the only type of messagebox I can find to use is the invalidPluginExecutionExperssion

    That doesn't really fit what I want as it stops the rest of the code from executing, i've looked into using javascript to create the textbox but so far been unsuccessful I'm assuming because I'm using a class library

    Any suggestions? 

    Thanks, Shaun

    Tuesday, June 3, 2014 7:57 AM
  • Hi Shaun,

    The only way to display a message box from a plugin is by using the "InvalidPluginExecution" thing that you tried; where the error will appear as a Business Process Error. Although it's something we don't like to see and might not apply for most cases (where you might just need to show an alert to the user rather than brining up that error popup), it's the only way to pass message from Plugin to the front end.

    However, there are workarounds for what you are trying to achieve. It works as follows:

    a. Add a hidden field to your form of type text.

    b. Using the Plugin to do whatever job you're doing in your Plugin, also update that field with the message you'd like to show.

    c. Write a JavaScript on Page Load of the CRM entity form and read the text field message and display it by using simple JavaScript or Xrm methods.

    but you need to keep in mind that the Plugin where you're doing your job has to be a synchronous Plugin; else the end user might not see the message instantly.


    Admin QuikView Solution for CRM 2013

    Tuesday, June 3, 2014 8:04 AM
  • Hi

    Do you have any example code of the solution you gave, not too experienced in Javascript working with. NET

    What I would like is when the user clicks save to save a new account to CRM, if one of the fields they filled out is a certain value then a message box will appear

    Thanks, Shaun

    Tuesday, June 3, 2014 8:16 AM
  • Hi Shaun,

    Looking at your requirement, I would say why not handle it solely on the CRM form side (client side) using JavaScript only? You say the message box will come up based on a value ENTERED BY THE USER.

    So, what you can do is wire up a JavaScript On Save of the entity. Check using JavaScript if the value the use filled is a certain value and based on that display a popup.

    You can a similar code like this:

    var fieldVal = Xrm.Page.getAttribute("your_field_name").getValue();
    
    if(your_check_condition)
    {
    	alert("your_message");
    }


    Admin QuikView Solution for CRM 2013

    Tuesday, June 3, 2014 8:20 AM
  • Hi,

    Thanks again for the quick replies, is there any web pages that could point me in the direction of how to set up the Javascript on save 

    The messagebox code you supplied looks great

    Thanks, Shaun

    Tuesday, June 3, 2014 8:46 AM