This topic contains 1 reply, has 0 voices, and was last updated by pcutler 7 years, 1 month ago.
-
AuthorPosts
-
October 19, 2017 at 12:54 pm #18228
NateSI have three separate scripts that all work in unison to load a suitelet page from the click (client script) on a button made from a user event script (before load). I’m pretty much done, but I can’t figure out a way to pass the current record id (the record in which the button that leads to the suitelet) to the suitelet so I can load information from that specific record. Ignore the record ids that are present in the suitelet script, they were just there for testing if the correct data is being pulled in. The suitelet loads up with everything I need in it from the record that I specify in the script source code and looks pretty much the way I want it ( I need to tweak a few things), all I need now is a way to pass the current record id to the suitelet so it will dynamically load records.
USER EVENT SCRIPT (BEFORE LOAD) THAT CREATES THE BUTTON:
Code:
function beforeload(type,form) {
if(type==’view’) {
form.addButton(‘custpage_suitelet_button’,’PDF-TEST’,’onButtonClick()’)
form.setScript(‘customscript_cust_add_button_suitelet’)
}
}
CLIENT SCRIPT THAT TRIGGERS ON THE BUTTON BEING CLICKED:Code:
function onButtonClick(){var recID = nlapiGetRecordId();
var URL = nlapiResolveURL(‘SUITELET’, ‘customscript_add_data_to_template’, ‘customdeploy1’)+’&custparam_id=’+recID;document.location = URL;
}
SUITELET THAT CREATES A CUSTOM PAGE:Code:
/**
* @NApiVersion 2.x
* @NScriptType suitelet
* @NModuleScope SameAccount
*/
// This example shows how to render search results into a pdf file.
// Note that this sample is a Suitelet, so it cannot be run in the debugger.
define([‘N/render’, ‘N/https’, ‘N/record’, ‘N/url’],
function(render, https, record, url) {
function onRequest(options, recordId)
{
var request = options.request;
var response = options.response;log.audit({
details: https.request.parameters
});
var xmlStr = ‘‘+
‘‘+
‘‘+
‘‘+
‘ ‘+
‘#if>‘+
‘‘+
‘‘+
‘‘+
‘‘+
‘2810 Stoner Court #1
North Liberty, IA 52317‘+
‘Questions? Call Us 888.977.6849 ‘+
‘‘+
‘ ‘+
‘ ‘+
‘‘+
‘+
‘‘+
‘
‘
${record@title}‘+
”+
‘‘+
‘Order Details ‘+
‘${record.billaddress@label} ‘+
‘${record.shipaddress@label} ‘+
‘‘+
‘‘+
‘Spotix Order#: ${record.tranid}
Web Order#: ${record.custbodystorefront_order}‘+
‘${record.billaddress} ‘+
‘${record.shipaddress} ‘+
‘‘+
”+
‘‘+
‘${deposit.paymentmethod@label} ‘+
‘${record.otherrefnum@label} ‘+
‘${record.shipmethod@label} ‘+
‘Est. Ship Date ‘+
‘‘+
‘‘+
‘${deposit.paymentmethod}
${record.terms}‘+
‘${record.otherrefnum} ‘+
‘${fulfillment.shipmethod} ‘+
‘${record.shipdate} ‘+
‘‘+
‘‘+
”+
‘‘+
‘ ‘+
‘‘+
‘${item.quantity@label} ‘+
‘${item.custcol_item_sku@label} ‘+
‘${item.item@label} ‘+
‘Price ‘+
‘${item.amount@label} ‘+
‘‘+
‘‘+
‘#if>‘+
‘${item.quantity} ‘+
‘${item.custcol_item_sku} ‘+
‘${item.custcol_item_full_name} ‘+
‘${item.rate} ‘+
‘${item.amount} ‘+
‘‘+
‘ #list>‘+
”+
‘
#if>‘+
‘‘+
‘For returns, exchanges, and shipping information: ‘+
‘${record.subtotal@label} ‘+
‘${record.subtotal} ‘+
‘‘+
‘‘+
‘Web: Spotix.com/policies ‘+
‘${record.taxtotal@label} (${record.taxrate}%) ‘+
‘${record.taxtotal} ‘+
‘‘+
‘‘+
‘E-mail: CustomerService@Spotix.com ‘+
‘${record.total@label} ‘+
‘${record.total} ‘+
‘‘+
”+
‘‘+
‘Thank you for your Order! ‘+
‘‘+
”+
‘‘+
‘‘+
‘‘+
‘‘+
‘‘;var salesOrder = record.load({
type: record.Type.SALES_ORDER,
id: 536778,
isDynamic: true
});
//NEED TO ADD LOGIC TO CHECK IF RECORD IS AN INVOICE
var customerDepositID = salesOrder.getSublistValue({
sublistId: ‘links’,
fieldId: ‘id’,
line: 1
});var itemFulfillmentID = salesOrder.getSublistValue({
sublistId: ‘links’,
fieldId: ‘id’,
line: 0});
var custDeposit = record.load({
type: record.Type.CUSTOMER_DEPOSIT,
id: customerDepositID,
isDynamic: true
});var itemFulfillment = record.load({
type: record.Type.ITEM_FULFILLMENT,
id: itemFulfillmentID,
isDynamic: true
});var renderer = render.create();
renderer.templateContent = xmlStr;renderer.addRecord({
templateName: ‘record’,
record: salesOrder
});renderer.addRecord({
templateName: ‘deposit’,
record: custDeposit
});renderer.addRecord({
templateName: ‘fulfillment’,
record: itemFulfillment
})var newfile = renderer.renderToResponse({
response: response
});
//var newfile = renderer.renderAsPdf();
//response.writeFile(newfile, false);}
return {
onRequest: onRequest
};
});
This is a cached copy. Click here to see the original post. -
October 19, 2017 at 1:35 pm #18229
pcutlerHow about
Code:
log.debug({ title: ‘Server Request Parameters’, details: options.request.parameters.custparam_id });
NateS replied on 10/19/2017, 01:55 PM: I’ll give it a try and let you know.
EDIT: This worked, thank you very much. I tried options.request.parameters, but I didn’t add the actual parameter id. I always miss some mundane details when I feel like I’m stuck on a particular issue.
-
AuthorPosts
You must be logged in to reply to this topic.