Reputation: 39
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?
` form.setScript('customscript_toloader')
form.addButton('custpagetestbutton', 'TEST button', 'createTO();');`
-Other script
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 < 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 & 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 < 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;
}
~rest of the code that does not execute~`
Upvotes: 0
Views: 3913
Reputation: 304
var steve = "form.setScript('customscript_toloader')" ; form.addButton('custpage_purchaseorder', 'Create TO', steve);
Not sure what you're trying to do in these lines but the third param in the addButton should just be your function name. For example:
form.addButton('custpage_purchaseorder', 'Create TO', 'createTO');
Upvotes: 2