cancel
Showing results for 
Search instead for 
Did you mean: 

MDK Attachment File Type

Vinay3
Participant
0 Kudos

Hi,

I had done the attachment in MDK but i am unable to get type type i means unable to what type of file is attached. I need to help to find the file type and file size.

{

"_Type": "Control.Type.FormCell.Attachment",

"_Name": "Attachment19",

"IsVisible": true,

"OnValueChange": "/RFI_UPDATESet/uploadAttachment.js",

"AttachmentActionType": [

"TakePhoto",

"SelectFile"

],

"AttachmentTitle": "Media",

"AllowedFileTypes": [

"jpg",

"png",

"gif",

"pdf",

"word",

"file",

"doc",

"csv"

],

"AttachmentAddTitle": "Camera"

},

{

"Value": "{filename}",

"_Type": "Control.Type.FormCell.SimpleProperty",

"_Name": "filename",

"IsEditable": true,

"IsVisible": true

},

Accepted Solutions (0)

Answers (1)

Answers (1)

mingkho
Advisor
Advisor
0 Kudos

Hello Vinay

When you get the value (e.g. via getValue method or the getClientData().AddedAttachment) of your attachment control in a rule, it'll return an array of attachments. Each item in the array is of type IAttachment. There's a property called contentType that allow you to check what type it is.

e.g.

// If you are calling this rule from the FormCell Attachment control's OnValueChange
// then the context will be the FormCell Attachment control itself. so 
// you can just call: let attachedFiles = context.getClientData().AddedAttachments;
// Otherwise find the control first in the current page first
// let myAttachementCtrl = context.evaluateTargetPathForAPI("#Control:MyAttachementCtrl");
// let attachedFiles = myAttachmentCtrl.getClientData().AddedAttachments

export default function uploadAttachment(context) { 
  // Get the added attachments
  let attachedFiles = context.getClientData().AddedAttachments;
  if (attachedFiles && attachedFiles.length > 0) {
    var len = attachedFiles.length;
    for (var i=0; i < len; i++) {
      var attachment = attachedFiles[I];
      // Do something with the content type
      // console.log(attachment.contentType);
    }
  }
}

Regards

Ming

Vinay3
Participant
0 Kudos

Hi Ming,

Thank You for reply.

I will try your give example. Actually i need to pass file name from rule to action and from action to Odata. If any example code is thr please help on this.

Thanks.

mingkho
Advisor
Advisor
0 Kudos

Hi Vinay, you can pass them via Action Binding, please refer to following documentation about Action Binding and Result.