To get Attachment details by using java script in d365

In Dynamics 365 CRM, To retrieve the attachments field name,type and Url by using javascript

Step 1: 
function GetName(executioncontext) 
{
var formcontext=executioncontext.getFormComtect();
var file= formcontext.getAttribute("new_attachment").getValue();

var view=file.fileUrl;
var attachment=file.fileName;
var attachments=file.mimtype;


var attach=attachments.split('/')[0];
if( attach== "image")
{
formcontext.getAttribute("new_attachmenttype").setValue("Image");
}
if( attach== "application")
{
formcontext.getAttribute("new_attachmenttype").setValue("Document");
}
if( attach== "video")
{
formcontext.getAttribute("new_attachmenttype").setValue("Video");
}
if( attach== "text")
{
formcontext.getAttribute("new_attachmenttype").setValue("Document");
}

}

Step 2: To get name and file type.

var attachments=file.mimtype;

We can get the file type.

Step 3: To get Url

var view=file.fileUrl;


Step 4: To split the file type.  I have used split.

var file= formcontext.getAttribute("new_attachment").getValue();

var attachments=file.mimtype;

var attach=attachments.split('/')[0];

 





1 comment:

  1. I really enjoyed your blog Thanks for sharing such an informative post.

    CRM Solutions

    ReplyDelete