I am working on a script that notifies the users i...
# suitescript
c
I am working on a script that notifies the users if a tax id number is already in use. I am using a fieldchanged and saveRecord function. I create a search and if the array returns a length greater than 1 it provides an error message and stop them from saving. I got it working, but I am creating and running the search in both the fieldChanged and saveRecord. Is there a better way of dealing with this?
c
Depends on this one. You could have a checkbox on the record that if the condition is true, is checked. Then save record would just look at the checkbox. You'd have to take into account setting the box to false as well.
Otherwise, maybe just run the search once on save and alert the line and stuff then?
c
Yea it may make more sense to just do it when they try to save. I wanted to provide an error prior to that, but I wanted to see if there was a workaround
c
In order to see the error you have to run a search so unless you're tracking it another way, you gotta run the search.
c
yea it just felt clunky having to run the search twice. I wish I could just pass the results from fieldChange to saveRecord
another question is do you know to search values with spaces? Ex: Tax ID is "330 5500" if I try to search that value in a regular save search using "IS" it isn't found, but if I used "Starts with" or "Contains" it does
c
try the equal to one
s
You might wanna add some userevent logic if someone tries to update the record inline or via csv, for example?
z
@Chris Are you kidding 😁... IS operator doesn't work if value to compare contains SPACE... I am going to "kill" myself if that is true
c
Well I don't think you have to worry. It seems to be working now. Maybe I just copied and pasted the incorrect number and that's why it wasn't being found
I thought it was a strange issue and couldn't believe it wouldn't work
Maybe I selected Tax Number instead of Tax ID
m
If you wanted the logic in both entry points you could use a variable that is declared outside of the entry points so it is available to both of them, or look into memoizing the search function
c
Thanks for the advice. I will take a look into that