I am so baffled by this. The UE script in the repl...
# suitescript
l
I am so baffled by this. The UE script in the reply section works on Create and Edit (manual) of the Expense Report transaction. I have another Suitelet script with submitFields action that practically edits the Expense Report. But, when triggered through the Suitelet, it does not get the value of the currency and other fields of the Expense Report. Why is that? Or is there a way to stop the Suitelet from triggering the UE? Thanks.
Copy code
function beforeSubmit(context) {
  
    var newTransaction = context.newRecord;
    var currencyCode = newTransaction.getValue('currency');
    log.debug('currencyCode:', currencyCode)
    
    var transactionDate = newTransaction.getValue('trandate');
    log.debug('transactionDate: ', transactionDate)
    
    var exchangeRate = currency.exchangeRate({
      source: currencyCode,
      target: 'AUD',
      date: transactionDate
    });
    log.debug('exchangeRate:', exchangeRate)

    var transTotal = newTransaction.getValue('total');
    log.debug('transTotal:', transTotal)
    
    var transCurrency = newTransaction.getValue('expensereportcurrency');
    log.debug('transCurrency:', transCurrency)
    
    var convertedAmount = exchangeRate * transTotal;
    log.debug('convertedAmount:', convertedAmount)

    if (transCurrency == '1') {
      newTransaction.setValue({
        fieldId: 'custbody_aaa_total_trans_amount_aud',
        value: transTotal
      });
    } else {
      newTransaction.setValue({
        fieldId: 'custbody_aaa_total_trans_amount_aud',
        value: convertedAmount
      });
    }
  }

  return {
    beforeSubmit: beforeSubmit
  };
k
SubmitFields uses inlineEdit and inline edit will only have the fields you are editing in the context.newRecord. You can load the record in afterSubmit for XEDIT context.executionContext or switch your suitelet to use a load and save of record. If you don’t want to trigger the UE at all from any suitelet you can either ignore it on the script record or add a if statement for the context type in your script.
b
l
Thank you both. I just added an if statement for the context type and it's now working.