I have a UE script (deployed on the case record) a...
# suitescript
m
I have a UE script (deployed on the case record) and a CS script (deployed on the specific case form). I am trying to (1) Display a button when a case record is in view mode - this works. (2) How can I open a new sales order form in edit mode upon button click? As a test, I am trying to first get the button function called in CS script from the UE script but this isn't happening. Both of the scripts are in the SuiteScript root folder. CS:
Copy code
function OPEN_SALES_ORDER_FORM() {
        dialog.alert({
            title: "Function Called",
            message: "TODO"
        });
    }
UE:
Copy code
function beforeLoad(context) {
            context.form.addButton({
                id: "custpage_so_button",
                label: "Create SO",
                functionName: "OPEN_SALES_ORDER_FORM"
            });
            context.form.clientScriptModulePath = "SuiteScripts/display_so_button_cs.js";
        }
b
your client script define function callback should return an object with a OPEN_SALES_ORDER_FORM key
m
thanks, will revert back to script
thank's, I added the return object and that now correctly calls the function when clicking the button. Is it possible to open a new record in edit mode?
b
use window.open in combination with url.resolveRecord
m
great, will have a crack at that - much thanks!
With this code I am able to open an existing SO, but how can I open a blank one. The recordId is required. And would it be possible to populate certain fields on the SO along with a line item using case data like the company name and other data.
function OPEN_SALES_ORDER_FORM() {         dialog.alert({             title: "Function Called",             message: "TODO"         });                  var output = url.resolveRecord({             recordType: 'salesorder',             recordId: 9286059,             isEditMode: true         });                  window.onbeforeunload = null;         window.open(output);     }     return {         pageInit: pageInit,         OPEN_SALES_ORDER_FORM: OPEN_SALES_ORDER_FORM     };
b
Probably want to be more clear about what you want
Basic options for records are to create a new one
Or edit an existing one
m
sorry, what I meant was - upon clicking the button I want to be able to create a new SO. I took a sample example from SuiteAnswer and the url.resolveRecord requires a recordId so not sure if this is the correct method to use
b
you want url.resolveTaskLink then
m
the url.resolveTaskLink does open a new SO, which is perfect. It accepts params as optional, but there are no examples of how to construct this. Ideally, I would like to set the company field and one line item by default:
options.params
"The Map object containing name/value pairs to describe the query." - not sure if this will allow it.
b
the params are url parameters
keys of the object become the keys of the url query and the values of the object become the values of the url query
expect to use client script or a user event script to fill in you default line item
m
so I understand what you are saying - url keys and values can be used to set the company name, but for line item I would need to use code in client/UE script....
Copy code
something like this: var entity_id = '&entity=129302'
        var so_url = url.resolveTaskLink('EDIT_TRAN_SALESORD', entity_id);
b
params should be an object, not a string
m
ah ok
that works
sorry, struggling to think how I would set a line: both of my scripts (client & UE) are deployed on the case record and since I can't pass data in the url query, would this mean I would need another script?
b
put the data in the url
m
So like this below? Entity works - set's the SO company, but not sure how we construct the equipment to set the line var entity_id = { entity: 129302};         var equipment = { line: 24463 };         var so_url = url.resolveTaskLink('EDIT_TRAN_SALESORD', entity_id, equipment);         window.onbeforeunload = null;         window.open(so_url);
b
you put all your keys and values in the same object
one level, just like the url parameters themselves
m
I tried item and then line as the key, then tried nested object like this, but none has yet set the item. The url did show the item value now that it's within one object var defaults = { entity: 129302, item: {item: 24463} };         var so_url = url.resolveTaskLink('EDIT_TRAN_SALESORD', defaults);
b
one level, key value pairs
no fancy objects for the values, only strings
as i said before, you will have to script the rest for the sublist setting
netsuite has specific functionality for url parameters
entity works as a parameter since it is also a default value
if you wanted to default the memo, you would use '&record.memo=value', since netsuite has undocumented functionality for defaulting the value of body fields
there is no known equivalent for sublist fields, so you have to do that yourself
m
thanks, the '&record.memo=value', is useful to know as there are other default values that I'd like to set and this works.
I thought you meant we could just pass the item id in the url and be able to set the line. So when you say: "script the rest for the sublist setting" - does this mean I would have to set every column on the line? I.e. quantity, rate, price level etc?
b
probably not both price level and rate, but yes
every column you would set in the ui