Any idea why I’m getting an error when using submi...
# suitescript
c
Any idea why I’m getting an error when using submitFields? “An unexpected SuiteScript error has occurred” This works:
Copy code
let existing_ts_record = record.load({type:record.Type.TIME_BILL, id: line.timesheet_id})
existing_ts_record.setValue({fieldId: "hours", value: parseFloat(line.duration).toFixed(4)})
existing_ts_record.save()
But this gives an error:
Copy code
record.submitFields({
    type: record.Type.TIME_BILL, 
    id: line.timesheet_id, 
    values: {hours: parseFloat(line.duration).toFixed(4)}
})
e
Contact support, they'll file a defect. I had a similar issue with contact records
c
K I’ll file a ticket. What’s odd the exact same script works when I run in the console clientside but not in a restlet. Frustrating
b
what value is in
parseFloat(line.duration).toFixed(4)
c
It’s the same value in both instances (load record and subfieldfields) but it it resolves to a float with 4 decimals. In my test, it was 2.45
b
im more interested in the output
the output of something that goes through .toFixed(4) wont be 2.45
c
I left off the trailing zeros, but: test = “2.45”
‘2.45’
parseFloat(test).toFixed(4)
‘2.4500’
The exact same value works when I use record.load > setvalue > record.save
b
meh, works for me
Copy code
require(["N/record"], function (record) {
  record.submitFields({
    type: "timebill",
    id: "1",
    values: { hours: "2.4500" },
  });
});
ends up being a time tracking record with 2:27 hours on it
c
Yeah the exact same call works when I execute via client script (or in the console on client side), just not in my restlet
b
that was in the suitescript debugger
c
Even when I hardcode the ‘hours’
b
from suitescript's perspective, there is no difference between
Copy code
parseFloat('2.45').toFixed(4)
or
Copy code
"2.4500"
everything in between is just complications to debugging
c
Even for a source value of say, “2.66666666666666666666667”?
b
by the time you reach suitescript's api, the
parseFloat('2.45').toFixed(4)
has already been run
Copy code
parseFloat('2.66666666666666666666667').toFixed(4)
and
Copy code
"2.6667"
are the same thing
c
so if I called the following, it would work? setValue({fieldId:“duration”, value: “2.6666666666666666666667")
I know what parsefloat does, I just wasn’t aware netsuite handles that as part of the call
b
no, im saying that the general rules of javascript says that
Copy code
parseFloat(line.duration).toFixed(4)})
runs before
Copy code
record.submitFields
c
Yes I understand that
I’m not sure what that has to do with my question though
I’m calling parsefloat/tofixed to truncate it to 4 decimals before setfield is called
b
you shouldnt expect that hardcoding a value would have a difference compared to running your function
suitescript's api doesnt care, it will only see the output of your toFixed
c
I know this
I hardcoded as a test to rule out that it was something wrong with the restlet call, since the soure data is submitted via POST request
The point I’m making is the behavior is different with the exact same input data between submitFields and setValue > record.save() when executing in the context of a restlet
b
they arent the same, one is a regular edit, the other an xedit
for me
"2.4500"
works for both record.submitFields and record.setValue
so you may want to check that there arent any customizations deployed to that record
c
It does for me too…. just not in a restlet context
b
same thing for a restlet for me
c
Interesting. I think I will have to open a ticket with Oracle then to figure out what the “unexpected suitescript” error is. Thank you for your help
e
Should you require it, you could reference defect 604550. In my case it was assembly builds, not contact records, and it was in a scheduled script context
226 Views