You'll need to test to make sure that works. Some...
# general
s
You'll need to test to make sure that works. Some SuiteScript calls fail when made on inactive records.
b
I'm very new to suitescripting. I plan on doing this with a beforeSubmit usereventscript. How can I determine whether the project is about to be set to inactive?
s
Usually, I do some testing to determine what can be detected and when. I'll create a new User event script, deployed on the record, and will have all three event types present. Then add logging on the fields you care about on both the old and new record. Let me see if I can dig up an example.
b
Thanks. It actually looks like they delete the record rather than set them to inactive
s
if that's the case, even better!
if not, here's a template that might work to test what changes can bet detected, and when
b
appreciated
s
userevent.js
b
projectExternalIdUpdate.js
Obviously, the external id will be cleared when it's deleted, but I just want to be absolutely certain in case something happens
s
Always a good idea. I code defensively wherever I can.
b
I feel like suitetalk was just thrown together without much thought behind it
literally nothing makes sense lol
s
It's a very old API. I am hoping the new SuiteTalk REST API provides more and better capabilities. Going to have to wait a while before it's generally available, though.
b
yeah
s
They claim it will support "SuiteQL" queries. Whatever that is. I am hoping it means I can do arbitrary ODBC-like queries, with JOINs and IN lists.
b
it does
idk why they have to reinvent the wheel tho and just use the standard graphql
s
So they can charge thousands of dollars for training and certification, is my guess
b
^^
for something that just won't seem to work right
and then when you call up to file a report, they'll say it's not a bug, but what you're requesting is an enhancement
for example in the current API: Every single Transaction Item type has a customFieldList on it... EXCEPT for the RequisitionItem. It's missing that field altogether in the API. They said it wasn't a bug and that I was requesting a new feature
nah, bro... you guys forgot it
s
They forget a lot of things. And make the end users work around it.
b
yep
for some reason it's not persisting the externalid
Untitled
that "Final External Id" shows it updated correctly, but then it isn't updated
message has been deleted
s
Yeah, I was afraid that might happen. Often with inactive records it won't let you change values, even via scripting.
b
This isn't an inactive record
s
oh, that's strange then
Maybe try forcing
entityId
to be a string, in case it's coming in as a numeric value
entityId   = String(currentRecord.getValue({fieldId: 'entityid'}))
b
ok
trying one other thing
nope the string thing didn't work either
s
Just as a test, try setting the external id to some static value like 'ItWorked789XYZ'
b
ok
s
make sure it's just not preventing you from updating the field
b
nope lol
the static value didn't work either
does that mean it doesn't submit the field and I have to do it manually?
s
Oh, you might have to.
But, I don't know. It seems like it should work. If doing that, I'd move the logic to afterSubmit.
Weird things can happen if you load/save a record in the middle of a beforeSubmit
b
I've had a lot of issues with changes persisting in the afterSubmit
because afterSubmit doesn't trigger until the record has already been saved in the database
s
right. well, so long as it is the only change being made, it may work. I know I have set externalid before in scripts. Unless there is some reason a User Even script can't touch it. Is it running as Administrator?
b
let me double check
it was set to "Current Role"
and I'm logged in as admin.
chagned it to run as admin and nothing. I'll change it to an afterSubmit and see what happens
s
the big downside to afterSubmit is that you have to do an explicit record load, set field, then save.
and it hits the database twice, so performance is also an issue, but in most cases not a noticeable one
b
ok
boom
that worked thanks
s
well, that's good
b
I appreciate your time
s
Not a problem. I am about to work on my own user event script to keep external id in sync with a custom field, so I will probably run into the same issue.