locked
Create Email Attachement using jscript crm 2011 How? RRS feed

  • Question

  • Hello  Experts

    How can I send an attachement as text document while creating an email  please provide some code

    Thanks and regards

    Murali

    Thursday, August 8, 2013 8:41 AM

Answers

  • Great. Thanks for letting us know. Can you mark this thread as answered to close it off.

    Thanks! 


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by 2014crm Saturday, August 10, 2013 12:55 PM
    Saturday, August 10, 2013 10:53 AM
    Answerer

All replies

  • Hi,

    This can be done quite easily using the code posted at  http://xrmmatrix.blogspot.co.uk/2011/06/creating-report-as-pdf-attachment-in.html

    The post uses reporting services to generate a pdf from within client side javascript - so you just need to change this to create a text file instead.

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"


    Thursday, August 8, 2013 8:52 AM
    Answerer
  • Hi,

    Thanks for reply it is helpful

    How can I write content to that attachement file (like textfile)  using javascript ,after writing i want to attach the file. is it possible like that?

    Thanks and regards

    Murali

    Thursday, August 8, 2013 9:07 AM
  • Hi,

    In the code, rather than use:

     var params = getReportingSession();

    use 

     var params = "Insert your text file content here"

    Also, rather than the mime type of "application/json", use "text/plain"

    Everything else is there in the code.

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, August 8, 2013 9:18 AM
    Answerer
  • Hi,

    I want to add activity mime attachment entity I am trying to add Body of this entity,the attachment is not created ,but I remove body the attachment is creating

    and also Filename also one issue. when I write path of file name the attachment is not creating .please see my code and suggest changes. 

    function CreateEmailAttachment(actvid) {


                      //get reporting session and use the params to convert a report in PDF

                      // var params = getReportingSession();

                      debugger;
                      //Email attachment parameters

                      var activitymimeattachment = Object();

                      activitymimeattachment.ObjectId = Object();

                      activitymimeattachment.ObjectId.LogicalName = "email";

                      activitymimeattachment.ObjectId.Id = actvid;

                      activitymimeattachment.ObjectTypeCode = "email",

                      activitymimeattachment.Subject = "File Attachment";

                      //activitymimeattachment.Body = "Sample content";

                      //SaveAsFile();
                      var sample="Hello World";

                      activitymimeattachment.FileName = "C:\Users\ashis\Desktop\Provider Route Information.txt";

                      //Attachment call

                      activitymimeattachment.MimeType = "application/txt";

                      SDK.JQuery.createRecord(activitymimeattachment, "ActivityMimeAttachment", ActivityMimeAttachmentCallBack, errorHandler);

                  }

    thanks and regards

    murali


    • Edited by 2014crm Thursday, August 8, 2013 1:06 PM
    Thursday, August 8, 2013 11:53 AM
  • Hi,

    The mimetype should be "text/plain" and the file name should simply be Provider Route Information.txt without the full path. 

    Are you asking how to upload a file from the local file system - if so, then you'll need something like : http://stackoverflow.com/questions/14446447/javascript-read-local-text-file

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, August 8, 2013 12:04 PM
    Answerer
  • Hi  scott Durow ,

    I changed as  you mentioned even the email attachemnt is not created.

    please check the code if any thing wrong.

                                                         

    function CreateEmailAttachment(actvid) {







                      var activitymimeattachment = Object();

                      activitymimeattachment.ObjectId = Object();

                      activitymimeattachment.ObjectId.LogicalName = "email";

                      activitymimeattachment.ObjectId.Id = actvid;

                      activitymimeattachment.ObjectTypeCode = "email",

                      activitymimeattachment.Subject = "File Attachment";

                      //activitymimeattachment.Body = "Sample content";

                      //SaveAsFile();
                      var sample="Hello World";
                      activitymimeattachment.Body = sample;
                      activitymimeattachment.FileName = "Provider Route Information.txt";

                      //Attachment call


                      activitymimeattachment.MimeType = "text/plain";


                      SDK.JQuery.createRecord(activitymimeattachment, "ActivityMimeAttachment", ActivityMimeAttachmentCallBack, errorHandler);

    The problem is here the body of email attachment .If I remove the'  Body ' attribute of attachement .the attachment is creating ,but I am not able to write the contents to that attachement. please tell how can I write content

    thanks and regards

    Murali


    • Edited by 2014crm Thursday, August 8, 2013 2:24 PM
    Thursday, August 8, 2013 2:02 PM
  • You are missing the step to base64 encode the text file - in the original code I pointed you at there is a function that base64 encodes the body.

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, August 9, 2013 10:57 PM
    Answerer
  • Hi Scott, Thanks for helping me.

    I used the base64encode function in Body still the contents are not visible  in that attachment . but the filesize showing 3 bytes . can you please correct this code.


                      var activitymimeattachment = Object();

                      activitymimeattachment.ObjectId = Object();

                      activitymimeattachment.ObjectId.LogicalName = "email";

                      activitymimeattachment.ObjectId.Id = actvid;

                      activitymimeattachment.ObjectTypeCode = "email",

                      activitymimeattachment.Subject = "File Attachment";

                    

              

                      var sample = new Array();
                      sample.push("sample");
                      sample.push("content");
                  
                      activitymimeattachment.Body = encode64(sample);                    
                      activitymimeattachment.FileName = "RoundTripRouteFinder.txt";                                                                   
                      activitymimeattachment.MimeType = "text/plain";

                      SDK.JQuery.createRecord(activitymimeattachment, "ActivityMimeAttachment", function ActivityMimeAttachmentCallBack(result) { }, errorHandler);

    Thanks and regards

    Murali

    Saturday, August 10, 2013 6:22 AM
  • Hi scott durow,

     The contents are written into attachment , many thanks for your help.

    Thanks and regards

    Muralikrishna

    Saturday, August 10, 2013 10:20 AM
  • Great. Thanks for letting us know. Can you mark this thread as answered to close it off.

    Thanks! 


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by 2014crm Saturday, August 10, 2013 12:55 PM
    Saturday, August 10, 2013 10:53 AM
    Answerer