0

I am struggling to find a way to add a button to a Suitelet that calls another function in the same suitelet. I have tried many things but I can not get anything to work. I also tried to create a client script and call the client script but the issue with that solution is I need to call another function in the Suitelet from the client script.

function Image(request, response){
 
  var form = nlapiCreateForm("Today's Checks", true);

  function next(count){
    //code here
    showImage(imageId);//call to another function
  }
  
  form.addButton('custpage_next','Next',"next();");
  response.writePage(form);
  
  showImage(id){
    //more code . . . 
    }
  }
kdub
  • 205
  • 1
  • 6
  • 14

1 Answers1

4

The suitelet runs server side. You need to enable client side code. Put the code you need into another file and use it to create a client script. Give it a useful id when you create it. You don't need to deploy the script. Then

form.setScript('customscript_clientscriptid');

Then you can use the functions from that file in your button code.

bknights
  • 14,408
  • 2
  • 18
  • 31
  • Thanks that really helped! However now I need to set a field value on the suitescript form with a variable that was set in the client script. I have tried nlapiSetFieldValue(. . . ) but that does not seem to work. How can I set a field value on the suitelet form from the client script? – kdub Nov 30 '15 at 23:26
  • I was able to figure out the solution to my comment above but I am unsure why it worked. The field I am using on the form is an inline html field. If I set the default value of my field using .setDefaultValue on the suitelet then I can set the value using the Client Script – kdub Nov 30 '15 at 23:52