hey everyone, I am trying to set a custom transact...
# suitescript
m
hey everyone, I am trying to set a custom transaction body field value (date field) in a scheduled script (2.0). I've used record.setValue( ) in Suitelets and I've used record.submitFields in Map/Reduce to basically do what I needed, but neither of those are working here. With the record.setValue() call, nothing happens, no errors, and a log after the call will fire. record.submitFields breaks because the record is in standard mode. Feel like this is something simple I am just missing. Thank you
b
share the code, preferably with whatever value you are using
m
var date = '04/01/2020';
var formatDate = format.parse({value:date, type:format.Type.DATE});
rec.setValue({
fieldId: 'custbody_late_po_date',
value: formatDate,
});
the formatDate will log as
2020-04-01T08:00:00.000Z
b
that looks correct
whats the value of
Copy code
runtime.getCurrentUser().getPreference({name: 'DATEFORMAT'})
m
M/D/YYYY
b
i believe you are supposed to use 4/1/2020 then, im not sure if that matters
m
Thank you. That didn't work either
b
your date setting code looks reasonable as far as i can tell
m
No errors or anything. It makes me think the field is not properly configured, but it look ok
b
you probably need to show more of your code
m
And that code to set the value on a date field I have used over and over again in other scripts succesfully
b
you also would want to make sure there are no user event or workflows overriding your value
m
I am not sure what else I can show. I've stripped this down to it's most basic to get this part to work. And no, there is no other event or workflow. The field is brand new, not used anywhere else.
I've worked mostly with User Event and Map/Reduce scripts. Is there something specific to a Scheduled Script that would prevent setValue( ) from working?
b
nope
what does your field look like
m
Store Value is checked, there are no restrictions set in the Access Tab . . .
message has been deleted
message has been deleted
b
this code, works for me
Copy code
/**
 *@NApiVersion 2.0
 *@NScriptType ScheduledScript
 */
define(["N/record", "N/format"], function (record, format) {
  function execute() {
    var rec = record.load({ type: record.Type.PURCHASE_ORDER, id: "1780" });
    var date = "4/1/2020";
    var formatDate = format.parse({ value: date, type: format.Type.DATE });
    rec.setValue({
      fieldId: "custbody_late_po_date",
      value: formatDate,
    });
    rec.save();
  }
  return {
    execute: execute,
  };
});
m
Interesting. Thanks. I'll keep digging.