Good Day y'all. I'm currently learning how to use ...
# general
b
Good Day y'all. I'm currently learning how to use suiteScript and I've a little project that would get the shipping value and increase It by x% on set the value back on a sales order record, by just on click of a button. I'm not looking to get the answer here, but rather some direction on which module to use. Some hints to get me through that jungle. mostly what i've been struggling with so far is how to get the field value once the field is updated by the user on the record. I guess there must be some kind of event listener, but I cannot make that work either. Well any kind of help would be appreciated, even if It's just pointing me to the right set of tutorials! best-
s
#C29HQS63G
b
a button unusually means you use N/currentRecord to manipulate the current record
b
@battk right, the problem is currentRecord isn't working. as soon as I use It, It says record isn't defined in var record = currentRecord.get()
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
 define(['N/record', 'N/currentRecord'],
 function(record, currentRecord) {
   function beforeLoad(context) {
     if(context.type != context.UserEventType.VIEW) 
     {
         var newSoRecord = context.newRecord;

         context.form.clientScriptFileId = 6416;

         var record = currentRecord.get();

         var matercost = record.getValue({
            fieldId:'trandate'
            });

         context.form.addButton({
         id: "custpage_calculatecommission",
         label: "Calculate Shipping",
         functionName: "calculatecommission("+ matercost +")"
       });
     }
   }
   
   return {
     beforeLoad: beforeLoad,
   };
 }
);
b
you will need to understand when your code is running
serverside code like user event scripts run on netsuite's servers
clientside code like client scripts run on the user's computer
s
Don't make local variables that are the same name as a module you are using either.
b
N/currentRecord is for client script code
b
ok. Better. So you can't retrieve a field server side and send It to the client via the function of the button?
s
Yes you can retrieve the value in the UserEvent and pass it in the function call to the client, check the thread you commented in suitescript for an example
b
you can, and the code you have is very close to how you would do it, which suggests that you dont really know what you are copying and pasting
b
So how do you get the field value server side? the thread I commented isn't self explanatory. I was hoping you could help
b
how familiar are you with the N/record module
b
hum I wouldn't say we are close to each other.
b
the beforeLoad entry point gives you the record being loaded in its parameters
you can use that to get (and set in certain cases) the values on the record
b
right, so I should be able to do something like var test = context.newRecord.getValue({fieldId: 'thefield'}) and then send test to my client via the function of the button.
b
you probably want to know a little about html buttons, but that button function is implemented as an onclick attribute for your button
so its basically a string that is evaluated clientside
that becomes important to know if your value is a string that will need quotes to be evaluated correctly
you probably want to understand How User Events are Executed, fair chance that you really want to be using N/currentRecord in your client script
b
Thanks, beside the button, no matter what I do the get.Value in the UE isn't working.
Copy code
define(['N/record'],
 function(record) {
   function beforeLoad(context) {
     if(context.type != context.UserEventType.VIEW) 
     {
         var newSoRecord = context.newRecord;

         var test = newSoRecord.getValue({
             fieldId: 'trandate'
         });
         log.debug({title:'ServerSide',details:test});
         context.form.clientScriptFileId = 6416;


         context.form.addButton({
         id: "custpage_calculateShippingRate",
         label: "Calculate Shipping",
         functionName: "calculatecommission("+ test +")"
       });
     }
   }
   
   return {
     beforeLoad: beforeLoad,
   };
 }
);
b
its my warning about how function name is a string that is evaluated
log your functionName before you set it
b
Hey thank you for your help, I don't think what I was trying to do can be done anyway.
b
you can try describing what you want done, but the basic goal of increase the shipping cost by a percentage is pretty doable
b
Yes I actually succeeded. It was easy. I just though that you could get the values server side and send It to the client, It was more logical and I wanted to learn how to do that as well. And I was stuck at sending a String to my functionName, but It's like you said, It's a syntax problem since I need the quote for the html interpretation client side. The documentation is vast, what is a good starting point to understand what I'm doing instead of copying? Thank you for your help
s
If you prefer to watch instaed of read, check out stoic software on youtube, lots of videos on suitescript development https://www.youtube.com/channel/UCXciP6DplQzzLIbreiBAsmg