how can we find the script owner email address?
# suitescript
a
how can we find the script owner email address?
p
On the employee record?
a
inside the script
owner email of the running script
@PNJ how can I find the owner inside the script
p
there is an owner field, if you can’t see it your likely looking at the deployment
a
yes, but how do you get the value for that field inside the script
script context doesn't have the id
so I can't load it and then find the employee id and then find the email from emp record
b
use Script.id to get the script id and then lookup the required information
N/query will be more direct in this case since it has access to the owner join
a
thanks
any example for that
b
N/search will require a search to get the owner's id, and then you can lookup the email from the owner id
a
any example for query join
p
what have you tried so far?
b
this one is pretty simple, make the query first in the ui
load the dataset in script, then copy the condition and columns
a
@battk how can I make the query in the UI?
b
expect to understand SuiteAnalytics Workbook before using N/query
you may be able to skip learning a lot about workbooks if you understand the Analytics Browser and use SuiteQL, but i personally like seeing the data im working with first
p
if you want to use suiteql:
var suiteletquery = "select * from suitelet join employee on suitelet.owner = employee.id"; // where id =
var results = q.runSuiteQL({ query:suiteletquery });
var rows = results.asMappedResults();
(
q
is
N/query
)
a
@PNJ so the suiteletquery will be like
"select * from suitelet join employee on suitelet.owner = employee.id where id = 8"
if the script id is 8
p
select * from suitelet join employee on suitelet.owner = employee.id where suitelet.id = 8
You have to qualify
id
because it is present in both tables
a
this one didn't work it sayd
unknown identifier
the query.create did work finally but it will return all the owners not for the running script
p
I have tested this in the console and it worked:
var suiteletquery = "select * from suitelet join employee on suitelet.owner = employee.id where suitelet.id=871";// -- where id =
var results = q.runSuiteQL({ query:suiteletquery });
var rows = results.asMappedResults();
a
how can I test it in console
p
open a transaction in edit mode. press F12. paste this into a snippet and run it:
require(['N/query']);
var q = require('N/query');
var suiteletquery = "select * from suitelet join employee on suitelet.owner = employee.id where suitelet.id=871";// -- where id =
var results = q.runSuiteQL({ query:suiteletquery });
var rows = results.asMappedResults();
console.log(rows);
a
yes
you are right
it is working in console
@PNJ The issue is string literal
in console when I type the number everything is ok
but in code when I attach the id like
Copy code
id = ${id}
p
Share the code that's not working
a
it will throw an error
p
Help us to help you....
a
Copy code
var suiteletquery = `select * from suitelet join employee on suitelet.owner = employee.id where suitelet.id=${id}`
var results = q.runSuiteQL({ query:suiteletquery });
var rows = results.asMappedResults();
if I change the ${id} with for example 8
which is the script id everything will work fine
b
a
we have SQL package for nodejs that will help with situations I'm not sure if we have something similar here
script.id
is the id field in the script
it's not the number
it's customscript_
b
now compare that to what pnj shared
his works for the internal id
a
how can I get internal id
b
you dont, you have to write your query using the script id
a
but that't not the issue
issue is string literal
I've change the id to script id and everything is ok
if you copy paste the script.id value
but if you use
${id}
like my code
it will throw an error
this one will throw an erro
Copy code
var suiteletquery = `select * from suitelet join employee on suitelet.owner = employee.id where suitelet.id=${id}`
var results = q.runSuiteQL({ query:suiteletquery });
var rows = results.asMappedResults();
but this one will work fine
Copy code
var suiteletquery = "select * from suitelet join employee on suitelet.owner = employee.id where suitelet.id= 'customscript_something'"
var results = q.runSuiteQL({ query:suiteletquery });
var rows = results.asMappedResults();
b
you are missing the valuable code that sets id variable
a
that's Script.id
Copy code
var id = runtime.getCurrentScript().id
var suiteletquery = `select * from suitelet join employee on suitelet.owner = employee.id where suitelet.id=${id}`
var results = q.runSuiteQL({ query:suiteletquery });
var rows = results.asMappedResults();
p
if you need to debug it in the script - it's a suitelet, so just remove the where clause and dump the whole lot to the screen
b
again, pnjs query was written for a number
p
without you sharing your entire script, this is impossible
b
the query you are using is still for a number
a
sorry this one is the correct one
Copy code
var id = runtime.getCurrentScript().id
var suiteletquery = `select * from suitelet join employee on suitelet.owner = employee.id where suitelet.scriptid=${id}`
var results = q.runSuiteQL({ query:suiteletquery });
var rows = results.asMappedResults();
b
specifically,
Copy code
where suitelet.scriptid='customscript_something'
and
Copy code
where suitelet.scriptid=customscript_something
are not the same thing
a
yes
so how can I fix that
p
id
b
the 2 character difference between the two parts of the query
a
but we can't get id
we can but I think that will make it harder
how can I add those 2 characters
I don't know how to add it
b
as in you dont know how to add the
'
character to your template string?
a
yes
b
same way you would any other character, put the
'
character in the correct place in your template string
in this case, before and after
${id}
a
thanks