Attachment upload and download optional

Hi Team,

I have process which contains 3 tasks. In first task I am uploading the file which is optional.For this I have used below script.
Regarding Download if there is no file, so the task getting loading error. Could you please suggest how to achieve if the file has null.

upload optional script:

<script cam-script type="text/form-script">
camForm.on('submit', function(evt) {
var indexOfUploadFileField = 0;
for (var i = 0; i < camForm.fields.length; i++) {
if (camForm.fields[i].variableName == 'attachemnt') {
if (camForm.fields[i].element.context.value == '') {
indexOfUploadFileField = i;
camForm.fields.splice(indexOfUploadFileField, 1);


Could you please help…how to set cam-download for file optional.