I am running the same search through a UserEvent s...
# suitescript
m
I am running the same search through a UserEvent script, and a Scheduled script, and one return value, and one doesn't.
Copy code
search.create({
  type: "transaction",
  filters: [
   ["type", "anyof", "CustDep"],
   "AND",
   ["internalid", "anyof", "3149"],
  ],
  columns: [
   "amountpaid",
  ],
})
The result of the search in the scheduled have value for
amountpaid
but in the UserEvent, it doesn't.
t
which one return the value?
m
The scheduled script
t
on the UE event when did you call the search?
m
beforeSubmit
t
can you show us the complete code 🙂
m
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType ScheduledScript
 */
define([
  "N/record",
  "N/search",
  "N/runtime",
  "N/task",
], function (record, search, runtime, task) {
  function execute(context) {
   let script = runtime.getCurrentScript();

   search.create({
    type: "transaction",
    filters: [
     ["type", "anyof", "CustDep"],
     "AND",
     ["internalid", "anyof", "3149"],
    ],
    columns: [
     "amountpaid",
    ],
   }).run().each(function (result) {
    if (script.getRemainingUsage() < 100) {
     task
      .create({
       taskType: task.TaskType.SCHEDULED_SCRIPT,
       scriptId: runtime.getCurrentScript().id,
       deploymentId: runtime.getCurrentScript().deploymentId,
      })
      .submit();
     return false;
    }

    let amountpaid = result.getValue("amountpaid");
    log.debug("amountpaid", amountpaid);
    
    return true;
   });
  }

  return {
   execute: execute,
  };
});
Scheduled
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(["N/search", "N/record"], function (
  search,
  record
) {
  function beforeSubmit(context) {
   try {
    search.create({
     type: "transaction",
     filters: [
      ["type", "anyof", "CustDep"],
      "AND",
      ["internalid", "anyof", "3149"],
     ],
     columns: [
      "amountpaid",
     ],
    }).run().each(function (result) {
     let amountpaid = result.getValue("amountpaid");
     log.debug("amountpaid", amountpaid);
     return false;
    });
   } catch (err) {
    log.debug("ERROR", err);
   }
  }

  return {beforeSubmit};
});
UserEvent
Scheduled
UserEvent
t
can you try loging of the "result" on your UE
m
{"recordType":"customerdeposit","id":"3149","values":{"amountpaid":".00"}}
t
not sure if this will work can you try removeing the double quotation on 3149. or try to parseInt("3149") the value
m
will give it a try, will see also if using N/query instead would help
👍 1
It worked with this.
Copy code
let resultSet = query.runSuiteQL({
  query:
   "SELECT foreignpaymentamountunused FROM transaction WHERE id = '" + context.newRecord.id + "' AND type = 'CustDep'",
});
🥳 1