This topic contains 1 reply, has 0 voices, and was last updated by SBatten 6 years, 6 months ago.
-
AuthorPosts
-
May 17, 2018 at 7:51 am #21256
BrandonI 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 first like (a log line) 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;
}
This is a cached copy. Click here to see the original post. -
May 18, 2018 at 3:52 am #21257
SBattenHi Brandon
I've done something similar recently:
function addButton(type, form)
{
//add a custom button on the form and specify the function name of the client script
form.addButton('custpage_Add', 'Copy to Quote',"copyToQuote();");
//this is the internal id of the client script that this script calls
form.setScript('customscript708');
}
Thanks
Sam
-
AuthorPosts
You must be logged in to reply to this topic.