Question
CGI
IN
Last activity: 7 Jul 2018 5:13 EDT
How to Validate File Type, while attaching to case
We have a requirement to restrict the File Type(s) that can be attached. We are using Pega 7.2.2.
Query: How to Validate/restrict File Type and display Message, while attaching to case.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems Inc.
US
Sorry I can't help with the exact code here. The approach I had in mind was to go after
var type = fileName.substring(fileName.lastIndexOf(".")+1); in the existing code, and use javascript if-else to throw in an alert and quit further processing if the type doesn't match your extension types. If it matches, then do whatever the OOTB code in the function does which is to attach the file.
If there is a problem you see with this approach, then let us know so that we can help from that point on.
Thanks.
EPAM Systems, Inc.
ES
Hi Rajasekhar,
Thanks for posting on PSC.
An OOTB "pxUploadFile" activity is called for uploading the file. Internally it invokes another OOTB activity "CallVirusCheck". You can tweak the code of this activity's Java step to check the file extension and restrict hereby.
Approach:
- "pxAttachName" property contains name the of the file attached. Call a validate rule on this and check for the extension.
Or else, you can use any other custom approach based on your requirement to validate the extension.
- User Page-Set-Message/Property-Set-Message method to configure a validation error which you want to display on the UI.
Hope it helps in your implementation, kindly notify by marking this post as answered/helpful for tracking purpose.
Regards,
Asif
CGI
IN
Thanks Asif.
In attach files window, I have tried
- "Drag and drop files here" option. Checked in tracer, pxUploadFile activity is not called.
- "Select file(s)" option. I have checked in tracer, pxUploadFile activity is not called.
Screen shot attached in main post. Please guide us.......
-
Hemanth Guptha Pasupula Subba
NCS Pte Ltd
SG
Hi RajaSekhar,
When we use the Drag and drop file or the Select File option, we are using the OOTB controls which call pyUploadFile activity(provided you have not overridden the default activity parameter). This activity is not final and can be used for testing the file type.
Regards,
Saikat
CGI
IN
Thanks Saikat.
We are using Pega 7.2.2
pyUploadFile activity is not called when we use the "Drag and Drop File" option.
NCS Pte Ltd
SG
Hi Rajasekhar,
In Pega 7.2.2 if you are using the pzMultiFilePath control(default for drag and drop), pyUploadFile is the default activity configured. Please check the control you are using and if you are overriding the default activity.
Regards,
Saikat
CGI
IN
In "Select File(s)" button, it is using pzMultiFilePath control i.e. Data-WorkAttach-File.pzBrowseAttachments {Pega-EndUserUI:07-10-21}.
We are talking about "Drag and drop files here" section Data-WorkAttach-File.pzMultiDragDrop {Pega-EndUserUI:07-10-15}, which use "pzMultiDragDropControlStandard" control.
Thanks in Advance.........
Pegasystems Inc.
US
You have done most of the research here Rajasekhar. Have you thought of creating your own version of pzMultiDragDropControlStandard control?
When the OOTB control is in play and you drag/drop a file, it invokes the below function by default -
function pzUploadFile(evt){
var fileName = evt.target.fileName ;
var type ="" ;
if (fileName.lastIndexOf(".")!=-1){
var type = fileName.substring(fileName.lastIndexOf(".")+1);
fileName = fileName.substring(0,fileName.lastIndexOf("."));
}
var data = evt.target.result;
if(data){
data = data.substring(data.indexOf(",")+1);
var sUrl = SafeURL_createFromURL(pega.u.d.url);
sUrl.put("pyActivity","Data-WorkAttach-File.pzDragDropMultiFileUpload");
sUrl.put("fileName",fileName);
sUrl.put("fileType", type);
var postData = new SafeURL();
postData.put("encodedFileSrc",data);
pega.u.d.asyncRequest("POST",sUrl,{success:refreshFileListSection,failure:refreshFileListSection},postData);
}else{
alert("Unable to load file using drag drop, Use Select/Browse Files option");
refreshFileListSection();
}
};
In the current function, Pega is doing nothing special with the type var(filetype). But could you possibly extend it from here and insert your own validation for your requirements?
You have done most of the research here Rajasekhar. Have you thought of creating your own version of pzMultiDragDropControlStandard control?
When the OOTB control is in play and you drag/drop a file, it invokes the below function by default -
function pzUploadFile(evt){
var fileName = evt.target.fileName ;
var type ="" ;
if (fileName.lastIndexOf(".")!=-1){
var type = fileName.substring(fileName.lastIndexOf(".")+1);
fileName = fileName.substring(0,fileName.lastIndexOf("."));
}
var data = evt.target.result;
if(data){
data = data.substring(data.indexOf(",")+1);
var sUrl = SafeURL_createFromURL(pega.u.d.url);
sUrl.put("pyActivity","Data-WorkAttach-File.pzDragDropMultiFileUpload");
sUrl.put("fileName",fileName);
sUrl.put("fileType", type);
var postData = new SafeURL();
postData.put("encodedFileSrc",data);
pega.u.d.asyncRequest("POST",sUrl,{success:refreshFileListSection,failure:refreshFileListSection},postData);
}else{
alert("Unable to load file using drag drop, Use Select/Browse Files option");
refreshFileListSection();
}
};
In the current function, Pega is doing nothing special with the type var(filetype). But could you possibly extend it from here and insert your own validation for your requirements?
Thanks,
Sunny
CGI
IN
Thanks Sunny....
Can you please help in extending above pzUploadFile function i.e. Pls share modified code with file type validation.
Thanks in Advance........
CGI
IN
Thanks Sunny....
Can you please help in extending above pzUploadFile function i.e. Pls share modified code with file type validation.
Thanks in Advance........
CGI
IN
Thanks Sunny....
Can you please help in extending above pzUploadFile function i.e. Pls share modified code with file type validation.
Thanks in Advance........
CGI
IN
Thanks Sunny....
Can you please help in extending above pzUploadFile function i.e. Pls share modified code with file type validation.
Thanks in Advance........
CGI
IN
Thanks Sunny....
Can you please help in extending above pzUploadFile function i.e. Pls share modified code with file type validation.
Thanks in Advance........
CGI
IN
Can you please help in extending above pzUploadFile function i.e. Pls share modified code with file type validation.
Thanks in Advance........
Accepted Solution
Pegasystems Inc.
US
Sorry I can't help with the exact code here. The approach I had in mind was to go after
var type = fileName.substring(fileName.lastIndexOf(".")+1); in the existing code, and use javascript if-else to throw in an alert and quit further processing if the type doesn't match your extension types. If it matches, then do whatever the OOTB code in the function does which is to attach the file.
If there is a problem you see with this approach, then let us know so that we can help from that point on.
Thanks.
CGI
IN
Thanks.....