Hello, I am working on my first SuiteScript and am...
# suitescript
j
Hello, I am working on my first SuiteScript and am not able to figure out why the code below returns “undefined” for var wo. This ClientScript is called from a UserEventScript that creates a button on the Work Order record. When all the currentRecord.CurrentRecord object Methods I tried returned “undefined” I assumed the current record was not being passed from the UserEventScript. I then defined var woId using Property “id” of currentReocrd.CurrentRecord and it returned the correct internal ID, so I am not sure what I am doing wrong. In this first phase, I am just trying to pass various work order field values to the ui alert, before moving on to the next phase and hopefully sending them via xml to a label printer. The ui alert box follows the code. I appreciate any help in figuring out what I am doing wrong. Thanks, John
b
you would probably have better luck using the N/record module to load the record
j
also you might need
tranid
instead of
tranId
b
the currentRecord stuff doesn't really work on view mode
j
I tried tranid and had the same result - same with all the Work Order fields. I will try N/Record module; will it automatically associate with the record from which the button was clicked? Thanks for the replies!
j
My approach with buttons is usually to get the data required for the button in the same
beforeLoad
event that creates the button.
What @battk meant was to do something like
var wo = record.load({ type: record.Type.WORK_ORDER, id: woId }).getValue({ fieldId: 'tranid' });
Could also use
search.lookupFields
j
That makes sense, let me see where that takes me. I also like the idea of getting the button's data in the user event script, but need to do some more research. I am working on things beyond my skills, but trying to address some of our needs while I continue to learn JS.
I added the record.load method and still return wo = undefined. I also tried using the actual record id instead of the woID variable and still returned undefined. Then tried breaking out the record.load from the Record.getValue method and got the same result. Not sure that it adds any value, but setting wo = RecObj returns wo = standard record. I have looked over the documentation multiple times and I don't see why this is not working. Here are snippets to show what I have done. Returns wo = undefined function printWoLabel() { var currentRecObj = currentRecord.get(); var woId = currentRecObj.id; var wo = record.load({ type: record.Type.WORK_ORDER, id: woId }).getValue({fieldId: 'tranId'}); dialog.alert({ title: "Future functionality", message: "Under construction - please check back later."+ " woId = " + woId + ", wo = " + wo }); } Returns wo = undefined. var RecObj = record.load({ type: record.Type.WORK_ORDER, id: woId }); var wo = RecObj.getValue('tranId'); Returns wo = undefined. Adding single quotes around the id has the same result. var RecObj = record.load({ type: record.Type.WORK_ORDER, id: 115370}); var wo = RecObj.getValue('tranId'); Returns wo = standard record. Adding single quotes around the id has the same result. var RecObj = record.load({ type: record.Type.WORK_ORDER, id: 115370}); var wo = RecObj; Thanks, John
b
it was mentioned before, but its
tranid
j
Bingo! that worked. My apologies, I tried both tranId and tranid when I was working with the N/currentRecord module and thought I had with the N/record module as well - but must not have. Doesn't help that I inadvertently used the NS Schema Browser instead of Record Browser, which has tranId. Thank you very much!
👍 1