By using this solution, we can get the file which is stored in file cabinet on the specific folder with the file name of a Return Authorization number or related to any RA details using Suitescript 2.0
Suitescript:
// salesOrderResult is an array of return authorization ids
try {
var returnAuthorizations = [];
for (var i = 0; i < salesOrderResult.length; i++) {
var returnsRec = record.load({
type: "returnauthorization",
id: salesOrderResult[i].id,
isDynamic: false,
defaultValues: null
});
var tranid = returnsRec.getValue("tranid");// will get the tranid of RMA which is RA****
var returnLabels = search.create({
type: "folder",
filters: [ ["internalid","anyof","1383246"], "AND", ["file.name","contains", tranid] ], //1383246 is the folder id of which all RA images will be stored
columns: [ search.createColumn({
name: "name",
join: "file",
label: "Name"
}),
search.createColumn({
name: "internalid",
join: "file",
label: "id"
})]
});
var labelImages = [];
returnLabels.run().each(function(result){
var fileName = result.getValue({
name: "name",
join: "file"
})
var fileId = result.getValue({ name: "internalid", join: "file" })
if (fileName) {
labelImages.push({imageName: fileName ? fileName: "", internalId: fileId ? fileId : ""})
}
return true;
});
for (var j = 0; j < labelImages.length; j++) {
if (labelImages[j].imageName === (tranid + "-ReturnLabel.png")) {
if (labelImages[j] && labelImages[j].internalId) {
var labelImageFile = file.load({
id: labelImages[j].internalId
});
returnAuthorizations.push({returns: tranid, label: labelImageFile.url})
} else {
returnAuthorizations.push({returns: tranid, label: ''})
}
}
}
}
return {
AdditionalFieldData: salesOrderResult,
returnAuthorizations: returnAuthorizations
};
} catch (error) {
log.error("ERROR @ fun", error);
return {}
}