So, I have the script shown below. It runs just fine the first time (I know this because the files are generated), but when it reaches the second currency loop, it just stops and throws a 500 error—with no output on the screen or in the logs. It would be great if the sandbox could display output in real time, like most IDEs do.
Code:
$now = datetime\now();
$today = datetime\today();
$j = 0;
while ($j < array\length(currenciesRequired)) {
$currency = array\at(currenciesRequired, $j);
output\printLine($currency);
$i = 0;
while ($i < array\length(systems1Ids)) {
$currentId = array\at(systems1Ids, $i);
record\update('System', $currentId, 'currentCurrency', $currency);
$name = string\concatenate(
record\attribute('System', $currentId, 'name'),
'_',
$currency,
ifThenElse(templateID == '64f08cee741184566', '-HAE', ''),
'.pdf'
);
output\printLine($name);
$pdfId = ext\pdf\generate('System', $currentId, '674f0e889f1b0bc77', $name);
record\update('Attachment', $currentId, 'field', 'file');
// Check if Document exists
ifThenElse(
record\exists('Document', 'name=', $name),
(
// Update existing document
record\update(
'Document',
record\findOne('Document', 'name', 'asc', 'name=', $name),
'fileId', $pdfId,
'createdAt', $now,
'modifiedAt', $now,
'publishDate', $today
)
),
(
// Create new document
$docId = record\create(
'Document',
'name', $name,
'publishDate', $today,
'status', 'Published',
'fileId', $pdfId
);
// Relate document to folder and system
record\relate('Document', $docId, 'folder', portalContactFolder.documentFolderId);
record\relate('System', $currentId, 'priceListDocuments', $docId);
)
);
$i = $i + 1;
}
$j = $j + 1;
}
status = 'Complete';

Comment