how to debug a Formula script when there is no output?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamie
    Senior Member
    • Aug 2025
    • 141

    #1

    how to debug a Formula script when there is no output?

    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';
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1773

    #2
    I think it is due to this problem, I also ran through once: https://forum.espocrm.com/forum/gene...495#post119495

    Comment

    • jamie
      Senior Member
      • Aug 2025
      • 141

      #3
      Originally posted by shalmaxb
      I think it is due to this problem, I also ran through once: https://forum.espocrm.com/forum/gene...495#post119495
      Thanks for that, though it turned out to be a timeout problem that i have had to up to near infinite

      Comment

      Working...