Can anyone help out on a button that calls a Suite...
# suitescript
x
Can anyone help out on a button that calls a Suitelet when you press it? I keep getting "Uncaught SyntaxError: identifier starts immediately after numeric literal" in the console after I press it, when nothing in my code would suggest that error should be thrown.
j
can you post your code for the button?
this is how I did something similar BTW
Copy code
var script_id = 123;
var deployment_id = 1;   
var params = {tx_id: tx_id};

var suitelet = url.resolveScript({scriptId: script_id, deploymentId: deployment_id, params: params});
		       	
context.form.addButton({
	id: 'custpage_call_sl_button', 
	label: 'Call Suitelet', 
	functionName: 'openURL("' + suitelet + '")'
});
x
Here's the UE (both buttons in this script show as I want them to)
define(['N/record', 'N/log', 'N/redirect', 'N/ui/serverWidget', 'N/url'],
function (record, log, redirect, ui, url) {
function beforeLoad(context) {
if (context.type == context.UserEventType.VIEW)
{
var form = context.form;
form.addButton({
id: 'custpage_btn_call_docengine',
label: 'Export',
functionName: "openWindow(" + context.newRecord.id + ");"
});
if (context.newRecord.getValue('custrecord_sc_inforouter_doc1_guid'))
{
form.addButton({
id: 'custpage_btn_call_inforouter',
label: 'View Doc 1',
functionName: "openWindowIR(" + context.newRecord.getValue('custrecord_sc_inforouter_doc1_guid') + ");"
});
log.debug({
title: 'we made it button',
details: context.newRecord.getValue('custrecord_sc_inforouter_doc1_guid')
});
}
context.form.clientScriptModulePath = "SuiteScripts/Libraries/docengineclient.js"
}
}
return {
beforeLoad: beforeLoad
};
});
And here's the client:
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(["N/ui/dialog", "N/log", 'N/url'], function (dialog, log, url) {
function pageInit(context) {
// This function should always remain blank.
}
function openWindow(intID) {
var scriptURL = url.resolveScript({
scriptId: 'customscript_sc_bs_docengine',
deploymentId: 'customdeploy1',
returnExternalUrl: false,
params: { "jrecid": intID }
});
log.debug({
title: 'we made it',
details: scriptURL
});
window.open(scriptURL);
}
function openWindowIR(intID) {
var scriptUR = url.resolveScript({
scriptId: 'customscript_sc_ir_suitelet',
deploymentId: 'customdeploy1',
returnExternalUrl: false,
params: { "jrecid": intID }
});
log.debug({
title: 'we made it',
details: scriptUR
});
window.open(scriptUR);
}
return {
pageInit: pageInit,
openWindow: openWindow,
openWindowIR: openWindowIR
}
});
The first button, the 'openWindow' works, but the second one, the 'openWindowIR' doesn't.
j
what happens if you replace
Copy code
functionName: "openWindowIR(" + context.newRecord.getValue('custrecord_sc_inforouter_doc1_guid') + ");"
                    });
with
Copy code
functionName: "openWindowIR(value);" 
                    });
where value is something that should work
need to figure out at what step something is going wrong
need to be sure that
Copy code
context.newRecord.getValue('custrecord_sc_inforouter_doc1_guid')
is returning what you expect
also, does your log.debug() in openWindowIR() execute or does the error happen before that?
x
Not getting the log.debug in openWindowIR
j
what line of code is throwing the error? You should be able to tell by clicking the error in the Chrome console
ok so I think openWindowIR() isn’t even running, error is before that
probably in your second addButton()
x
Yeah, when I replace that context.newRecord value with an actual value that should be passed, I still get the same error
b
If your guid is a string, it needs quotes
x
@battk would a single quote work, or would it need to be double?
Where I do something like this: "openWindowIR(" + "'" + context.newRecord.getValue('custrecord_sc_inforouter_doc1_guid') + "'" + ");"
b
Same rules as normal javascript
Either single or double works, with each one using a different escape mechanism
Your modified code essentially is the same as the old
An empty string is not a quote
x
It has a quote in it.
A single quote. And it actually worked.
b
turns out im bad at counting ticks