javascript缺失;在for-loop初始化器之后(未知来源

时间:2017-03-03 20:41:19

标签: javascript

以下代码是我试图运行的javascript(没有导入或初始变量声明,即使用的导入函数和下面显示的triggerStatus等变量已经声明但未粘贴)。运行时得到的错误是Error Running Script [scriptToRun.js]:com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EvaluatorException: missing ; after for-loop initializer (<Unknown source>#49) in <Unknown source> at line number 49

function runScript() {
  let (survey = newDocument,
    statusQuery = new AeSpcsrvySDTO()) {
    logger.fine('Space survey [' + survey.spaceSurvey + ']');
    // Look up the status
    statusQuery.statusCode = survey.statusCode;
    let (statuses = new StatusServiceImpl(SystemContext.getInstance()).findByDTO(statusQuery, null)) {
      let (status = statuses.get(0)) {
        logger.fine('Space survey [' + survey.spaceSurvey + ']'
                      + ' status [' + survey.statusCode + ']'
                      + ' completeYn [' + AeSpcsrvySCompleteYN.valueOfFromCode(status.completeYn).name() + ']');
        if (status.completeYn != triggerStatus.code) {
          logger.fine('Ignoring space survey [' + survey.spaceSurvey + ']');
          return;
        }
        logger.fine('Space survey [' + survey.spaceSurvey + ']'
                      + ' has ' + survey.aeSpcsrvyLocDTOList.size() + ' locations');
        for (let location in Iterator(survey.aeSpcsrvyLocDTOList)) {
          logger.fine('Space survey [' + location.spaceSurvey + ']'
                        + ' region [' + location.regionCode + ']'
                        + ' facility [' + location.facId + ']'
                        + ' property [' + location.bldg + ']'
                        + ' location [' + location.locId + ']');
          let (highestUsagePercent = BigDecimal.ZERO,
               highestUsage = null) {
            for (let occupancy in Iterator(location.aeSpcsrvyOccDTOList)) {
              logger.fine('Space survey [' + occupancy.spaceSurvey + ']'
                            + ' region [' + occupancy.regionCode + ']'
                            + ' facility [' + occupancy.facId + ']'
                            + ' property [' + occupancy.bldg + ']'
                            + ' location [' + occupancy.locId + ']'
                            + ' seq [' + occupancy.seq + ']'
                            + ' percent [' + occupancy.percentOccupancy + ']');
              let (proration = occupancy.percentOccupancy.movePointLeft(2)) {
                for (let usage in Iterator(occupancy.aeSpcsrvyOccUsgDTOList)) {
                  logger.fine('Space survey [' + usage.spaceSurvey + ']'
                                + ' region [' + usage.regionCode + ']'
                                + ' facility [' + usage.facId + ']'
                                + ' property [' + usage.bldg + ']'
                                + ' location [' + usage.locId + ']'
                                + ' seq [' + usage.seq + ']'
                                + ' sub seq [' + usage.subSeq + ']'
                                + ' usage code [' + usage.usageCode + ']'
                                + ' percent [' + usage.usagePercent + ']');
                  if (usage.usageCode && usage.usagePercent
                    // There's a validation for <= 100, but not for > 0.
                    && usage.usagePercent.compareTo(BigDecimal.ZERO) > 0) {
                    let (proratedUsagePercent = usage.usagePercent.multiply(proration)) {
                      if (proratedUsagePercent.compareTo(highestUsagePercent) > 0
                        || (proratedUsagePercent.compareTo(highestUsagePercent) == 0
                        && usage.usageCode.compareTo(highestUsage.usageCode) < 0)) {
                        highestUsage = usage;
                        highestUsagePercent = proratedUsagePercent;
                        logger.fine('New highest usage percent is [' + highestUsagePercent + ']');
                      }
                    }
                  }
                }
              }
            }
            if (highestUsage) {
              // Look up the location and update the usage.
              let (locationKey = new AeBLocDPK(highestUsage.regionCode, highestUsage.facId,
                                               highestUsage.bldg, highestUsage.locId),
                   serviceImpl = new PropertyServiceImpl(SystemContext.getInstance())) {
                let (location = serviceImpl.findByPrimaryKey(locationKey, false)) {
                  location.usageCode = highestUsage.usageCode;
                  serviceImpl.save(location, false, false);
                }
              }
            }
          }
        }
      }
    }
  }
}

查看指定的第49行和周围的循环语法,我没有看到问题,我错过了什么?

感谢

更新 使用AP进行更改。建议我收到一个新错误:当前代码(错误第3行:缺失;在声明之前):

function runScript() {
    'use strict';
    let survey = newDocument,
        statusQuery = new AeSpcsrvySDTO();
    logger.fine('Space survey [' + survey.spaceSurvey + ']');
    // Look up the status
    statusQuery.statusCode = survey.statusCode;
    let statuses = new StatusServiceImpl(SystemContext.getInstance()).findByDTO(statusQuery, null);
    let status = statuses.get(0);
    logger.fine('Space survey [' + survey.spaceSurvey + ']' +
        ' status [' + survey.statusCode + ']' +
        ' completeYn [' + AeSpcsrvySCompleteYN.valueOfFromCode(status.completeYn).name() + ']');
    if (status.completeYn != triggerStatus.code) {
        logger.fine('Ignoring space survey [' + survey.spaceSurvey + ']');
        return;
    }
    logger.fine('Space survey [' + survey.spaceSurvey + ']' +
        ' has ' + survey.aeSpcsrvyLocDTOList.size() + ' locations');
    for (let location in Iterator(survey.aeSpcsrvyLocDTOList)) {
        logger.fine('Space survey [' + location.spaceSurvey + ']' +
            ' region [' + location.regionCode + ']' +
            ' facility [' + location.facId + ']' +
            ' property [' + location.bldg + ']' +
            ' location [' + location.locId + ']');
        let highestUsagePercent = BigDecimal.ZERO,
            highestUsage = null;
        for (let occupancy in Iterator(location.aeSpcsrvyOccDTOList)) {
            logger.fine('Space survey [' + occupancy.spaceSurvey + ']' +
                ' region [' + occupancy.regionCode + ']' +
                ' facility [' + occupancy.facId + ']' +
                ' property [' + occupancy.bldg + ']' +
                ' location [' + occupancy.locId + ']' +
                ' seq [' + occupancy.seq + ']' +
                ' percent [' + occupancy.percentOccupancy + ']');
            let proration = occupancy.percentOccupancy.movePointLeft(2);
            for (let usage in Iterator(occupancy.aeSpcsrvyOccUsgDTOList)) {
                logger.fine('Space survey [' + usage.spaceSurvey + ']' +
                    ' region [' + usage.regionCode + ']' +
                    ' facility [' + usage.facId + ']' +
                    ' property [' + usage.bldg + ']' +
                    ' location [' + usage.locId + ']' +
                    ' seq [' + usage.seq + ']' +
                    ' sub seq [' + usage.subSeq + ']' +
                    ' usage code [' + usage.usageCode + ']' +
                    ' percent [' + usage.usagePercent + ']');
                if (usage.usageCode && usage.usagePercent
                    // There's a validation for <= 100, but not for > 0.
                    &&
                    usage.usagePercent.compareTo(BigDecimal.ZERO) > 0) {
                    let proratedUsagePercent = usage.usagePercent.multiply(proration);
                    if (proratedUsagePercent.compareTo(highestUsagePercent) > 0 ||
                        (proratedUsagePercent.compareTo(highestUsagePercent) == 0 &&
                            usage.usageCode.compareTo(highestUsage.usageCode) < 0)) {
                        highestUsage = usage;
                        highestUsagePercent = proratedUsagePercent;
                        logger.fine('New highest usage percent is [' + highestUsagePercent + ']');
                    }

                }
            }

        }
        if (highestUsage) {
            // Look up the location and update the usage.
            let locationKey = new AeBLocDPK(highestUsage.regionCode, highestUsage.facId, highestUsage.bldg, highestUsage.locId),
                serviceImpl = new PropertyServiceImpl(SystemContext.getInstance());
            let location = serviceImpl.findByPrimaryKey(locationKey, false);
            location.usageCode = highestUsage.usageCode;
            serviceImpl.save(location, false, false);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

不确定您要使用此块实现的目标:

 let (proratedUsagePercent = usage.usagePercent.multiply(proration)) {
                      if (proratedUsagePercent.compareTo(highestUsagePercent) > 0
                        || (proratedUsagePercent.compareTo(highestUsagePercent) == 0
                        && usage.usageCode.compareTo(highestUsage.usageCode) < 0)) {
                        highestUsage = usage;
                        highestUsagePercent = proratedUsagePercent;
                        logger.fine('New highest usage percent is [' + highestUsagePercent + ']');
                      }
                    }

您无法在let expression前添加块,也可以将其更改为:

let proratedUsagePercent = usage.usagePercent.multiply(proration)
if (proratedUsagePercent.compareTo(highestUsagePercent) > 0
                    || (proratedUsagePercent.compareTo(highestUsagePercent) == 0
                    && usage.usageCode.compareTo(highestUsage.usageCode) < 0)) {
                    highestUsage = usage;
                    highestUsagePercent = proratedUsagePercent;
                    logger.fine('New highest usage percent is [' + highestUsagePercent + ']');
                  }

另外:也许您的浏览器可能不支持let declaration strict mode之外的var。将其替换为'use strict;'或将python_packages(带引号)添加到您的函数顶部。