Hey all, I have what I think will be a pretty simp...
# suitescript
m
Hey all, I have what I think will be a pretty simple question. Working in an User Event script, beforeSubmit, I am trying to determine the best way to check for a transaction (sales order) that is being copied. I found that when the copy action is selected, the resulting beforeLoad shows the
context.type
as copy, but of course when you save, the type in the beforeSubmit changes from copy to create, which makes sense, but I need to know in a beforeLoad when a new transaction is coming from a copy or is actually newly create. Thank you!
a
haven't tested, but off the top of my head can you check the value of
createdfrom
? if that references another sales order then that would mean its a copy?
m
@Anthony OConnor I can log that value and it’s empty. I see that field listed in the records browser, but its non existent on our sales orders.
a
hmm, so thinking about this more, this isn't a "simple" question, or at least the answer isn't simple, there's no easy way to get the context from the before load and pass that to the beforeSubmit to drive your logic. I guess I'd take a different approach... What is the logic you're trying to prevent for a COPY that you allow for a regular CREATE?
m
It has to do with some custom tax code for speciality items that have highly variable taxes or restrictions based on jurisdiction. So, orders get copied with a lot of custom body fields set with certain values that are used in the tax code. I think the answer is to check for CREATE and then the value of all those fields, but I was hoping for a better or easier way, like just one, non-custom field like
createdfrom
or the
context.type
indicating a way
a
Right, that's what I'd suggest, I know its not a simple solution, but it WILL work 🙂
m

https://media.giphy.com/media/4Q05SFwqzqP9tTAIup/giphy-downsized.gif

🤣 1
but seriously, yea, thanks . . . that’s apparently going to be the only way. thanks for the ideas though
goodluck 1
e
You could detect
COPY
during
beforeLoad
and set a hidden field value to something that your
beforeSubmit
could pick up. It might be Yet Another Custom Field, but adding an "Is a Copy" checkbox that gets set during
beforeLoad
of a COPY action should be detectable by a subsequent
beforeSubmit
There are some limitations as to the types of fields that can be set during
beforeLoad
, but I think this is worth a try.
a
hmm?
e
a Copy isn't loading a record
(I don't think 😄 )
That's my suspicion anyway, which is why I made the suggestion
In other words, I believe a Copy falls under the next bullet, not the one you highlighted
👍 1
a
LOL err huh okay, interesting, I'd be curious to know if that works, if you try it @Melissa please update us here!
m
thanks y’all!! I am off for today but will give this a whirl first thing tomorrow and report back!
n
Maybe add a new field on beforeLoad, detect COPY and default the new field's value rather than add "Yet Another Custom Field", NB presumes you can see a field added this way in beforeSubmit.
t
Just throwing another idea in the pot, you could run a beforeload ue on copy that'll remove the said taxcode field on the lines The advantage is supposing if your other script fills things in before submit and its not a mandatory field that blocks saving
m
hey all, first of all, @erictgrubaugh’s idea worked! @Anthony OConnor So, that’s an option, but I also like dukky’s idea because then I could run also the base tax code without clearing later or checking for things or yea, having saves blocked. So, can I also remove one line in the item sublist in beforeLoad?? Thanks everyone!
👍 1
c
@erictgrubaugh Thoughts on using N/session or N/cache to ferry the context value across entry points rather than a custom field?
a
you'd need to id the record somehow, since it hasn't been saved yet it doesn't have an id, so how would you do that?
e
I have no doubt you could come up with a working solution with either of those. My general experience with those modules is that it just requires too much additional code for things like @Anthony OConnor is mentioning or re-hydrating the cache, and it just ends up being not worth it. A hidden field made by the script seems like a well-understood approach that will get the job done clearly and concisely. That's not to say there are never good uses for those modules or that this is the most optimal approach, but I'm not sure that you'd gain enough of anything to go for the most optimal approach here.
n
Potentially on a UE script you could make use of :
Copy code
let objSession = runtime.getCurrentSession();
to store data but you need to have a unique key since the data is visible across multiple instances of a UE script. I have done this and used the recordid as the key on edit, but of course on create, before submit you don't have that so... back to the custom field, potentially added beforeLoad.
c
The unique ID was my main sticking point for this approach too, and I couldn't readily come up with a robust solution - glad to know it's not just me 😄 thanks folks
👍🏻 1