I've got a UE adding a button to a sublist that ca...
# suitescript
p
I've got a UE adding a button to a sublist that calls a CS function, when it hits the CS function I'm looking to access the standard scriptContext and perform some checks, having difficulties finding how to load that in, if anyone could make a suggestion.
👀 1
u
You mean you want to access the record object?
p
indeed
u
Ok
you are using SS1.0 or SS2.0?
p
2.0
u
Ok.
There is module 'N/currentRecord'.
define(['N/currentRecord'], _function_(_currentRecord_) {
_function_ customButtonHandler() {
_var_ recordObj = _currentRecord_.get();
    
}
    
return {
        
customButtonHandler: customButtonHandler
    
}
})
Note: If you are in edit mode, this will return a dynamic record. means you can access all sublists and can do everything that u can in a clientscript entrypoint. In View mode it will only return a readonly static object.
p
I had tried something very similar, however once putting the function inside the define etc, it was just reporting the function as undefined when pressing the button, that behaviour is still occuring
u
you have to return it at the end
like I am returning an object containing the function reference.
p
Yes, I am doing that. still no luck oddly,
u
can I see the code where you are calling the function and the client script?
I mean the UE and the client script
p
Copy code
if(scriptContext.type != scriptContext.UserEventType.VIEW) {
    var list = scriptContext.form.getSublist('item');
    list.addButton({
        id: 'custpage_add_po_items',
        label: 'Add PO Items',
        functionName: 'addPOItems'
    });
}
is the UE, in a beforeload
u
and the client Script?
p
I've incorporated the CS into the prebuilt webstorm template, but it is as follows with the additional functions removed
Copy code
define(['N/record', 'N/search'],

function(record, search) {

  function addPOItems(){

        console.log('test');

    }
       return {
        addPOItems: addPOItems
    };
)};
u
O I get it
You see u need to tell the form about the client script. In UE, add this line before you add the button,
_scriptContext_.form.clientScriptFileId = clientScriptFileInternalId;
p
that has done it, I guess thats a better problem to have than me thinking the record wasn't loading! Thank you for the assistance, greatly appreciated
1
u
Welcome!