mg2017
03/26/2024, 4:16 PMconst sourceTagStart = '<AddtlRmtInf>';
const sourceTagEnd = '</AddtlRmtInf>';
const destinationTagStart = '<AddtlNtryInf>';
const destinationTagEnd = '</AddtlNtryInf>';
// Extract values between source tags
const tagValues = [];
let startIndex = fileContent.indexOf(sourceTagStart);
let endIndex;
while (startIndex !== -1) {
endIndex = fileContent.indexOf(sourceTagEnd, startIndex + sourceTagStart.length);
if (endIndex === -1) {
log.error({title: 'End tag not found', details: 'The end tag was not found in the file content.'});
return;
}
tagValues.push(fileContent.substring(startIndex + sourceTagStart.length, endIndex));
startIndex = fileContent.indexOf(sourceTagStart, endIndex + sourceTagEnd.length);
}
log.debug({title: 'Tag Values', details: tagValues}); //
[
"Hello 1",
"Hello 2",
"Hello 3"
]
// Replace destination tags with values
startIndex = fileContent.indexOf(destinationTagStart);
let tagIndex = 0;
while (startIndex !== -1 && tagIndex < tagValues.length) {
endIndex = fileContent.indexOf(destinationTagEnd, startIndex + destinationTagStart.length);
if (endIndex === -1) {
log.error({title: 'End tag not found', details: 'The end tag was not found in the file content.'});
return;
}
fileContent = fileContent.substring(0, startIndex + destinationTagStart.length) +
tagValues[tagIndex] +
fileContent.substring(endIndex);
tagIndex++;
startIndex = fileContent.indexOf(destinationTagStart, endIndex + destinationTagEnd.length);
}
// Save the updated file
const updatedFile = file.create({
name: myFile.name,
fileType: myFile.fileType,
contents: fileContent,
folder: myFile.folder
});
const updatedFileId = updatedFile.save();
log.debug({title: 'Updated File ID', details: updatedFileId});
erictgrubaugh
03/26/2024, 4:24 PMerictgrubaugh
03/26/2024, 4:33 PMerictgrubaugh
03/26/2024, 4:41 PMShawn Talbert
03/28/2024, 2:28 PM