Professionals- I have added a custom button (in a ...
# suitescript
a
Professionals- I have added a custom button (in a User Event script, beforeLoad) that shows on the Sales Order screen in view mode. When the user clicks the custom button, I call a Suitelet to do some operations. But on my Client Script, before I call the Suitelet, I need to validate that a couple of fields are populated. When I try to get the values of these fields, with currentRecord.get().getValue, I get undefined. I can only get the Sales Order Id (which I am using to call the Suitelet). The only thing that works is to actually load the Sales Order record with record.load() using the id. Then I can get the fields okay. The issue is that this takes a while, I assume it does an ajax operation behind the scenes. Finaly, the question: is there a better way to access the fields of the Sales Order from a Client Script in view mode than loading the record again?
b
you might want to do the validation logic in the beforeLoad
a
hmm, ok, something like disabling the button
but the behavior I see in the client script in view mode, is normal, right? the whole record is not available, correct?
a
I think client script doesnt work in view mode
a
well, not the standard entry points, but you can add a button in a User Event script, beforeLoad, and provide a client module code. When you click the button, the code in the client module runs. The issue is that if you do a currentRecord.get(), you only get the record shell, not all fields
if you want all fields, you must record.load() the record, which is a bit slow and, in my opinion, unnecessary…
a
you will encounter problems wherein butons that call suitelet and you combine it with a client script attachement on the user event.
a solution that you might do ... is to load those record that you want to check on the userLoad and if you dont want to be viewed make sure you set it as hidden. therefore your currentRecord.get() can still see it.
a
I had this same issue recently, and the currentRecord.get() function only pulls a few things like the record id, type, and isDynamic. What I did to get around it, is you can still use the search module and when the button is pressed i ran a saved search against only that record for the fields I needed.
it worked out nicely.
a
thanks, yes, I did a record.load, but a search could be good too. The only issue is that it is a bit slow….
s
I'd take a record.load over a search for same.
a
okay, thanks all for your help