title: suitescript run a function on a button click
body: <p>Redux:
  I want run a Script on a button click (because you cannot run a function in your script ona  button click) I've followed the Suitescript documentation and am only able to get the second log to run. Any idea?</p>
  
  <pre><code>` form.setScript('customscript_toloader')
   form.addButton('custpagetestbutton', 'TEST button', 'createTO();');`
  </code></pre>
  
  <p>-Other script</p>
  
  <pre><code>function createTO() //(request, response)
  {   
  alert("This function was called");
  //variable set up
      nlapiLogExecution('DEBUG', 'script', 'runs 1');
      var POID ;
      var POType ;
      var PORecord;
      var lines;
    nlapiLogExecution('DEBUG', 'script', 'runs 2');
      var arrayName = new Array();
      var arrayQty = new Array();
      PORecord = nlapiGetNewRecord();
      lines = PORecord.getLineItemCount('item');
      POID = nlapiGetRecordId();
      POTYPE = nlapiGetRecordType();
      // get name and quantity
      for ( var i = 1; i &lt; lines + 1 ; i++ )
      {
          arrayName[i] = PORecord.getLineItemValue('item', 'item', i ); 
          arrayQty[i] = PORecord.getLineItemValue('item', 'quantity' , i);
      }
      nlapiLogExecution('DEBUG', 'script', 'runs 3');
  
      //creates to and changes focus
      var TOrecord = nlapiCreateRecord ('transferorder');
      var TOrecordID = TOrecord.getId();
      TOrecord.setFieldValue('customform',128);
      //subsidiaries CC bedford id is 2
      TOrecord.setFieldValue('subsidiary',2);
      //testing for location and transfer location, 144 &amp; 145
      TOrecord.setFieldValue('location',144);
      TOrecord.setFieldValue('transferlocation',145);
      TOrecord.setFieldValue('memo', 'PO: ' + POID );
      TOrecord.setFieldValue('employee',nlapiGetContext().getUser());
      //TOrecord.setFieldValue('department',"C-C");
  
      //set name and quantity
      for ( var j = 1; j &lt; lines +1  ; j++ )
      {
          arrayName[j] = parseInt(arrayName[j]); 
          TOrecord.setLineItemValue("item", "item", j , arrayName[j] );
          TOrecord.setLineItemValue("item", "quantity", j , parseInt(arrayQty[j])); //added parse int, should work
  
      }
  
  
      // set the item and location values on the currently selected line
      nlapiSetCurrentLineItemValue('item', 'location', 6);
      // commit the line to the database
      //nlapiCommitLineItem('item');
  
      var TOResult = nlapiSubmitRecord(TOrecord, true, true);
      var TOTranID= nlapiLookupField('transferorder', TOResult, 'tranid');
      var poURL = nlapiResolveURL('RECORD', 'transferorder', TOResult);
  
      nlapiSetRedirectURL('RECORD','transferorder', TOResult);
      return;
       }
  </code></pre>
  
  <p>~rest of the code that does not execute~`</p>