How could we get all script name and script id in array I want it to be shown in dropdown in my application.
Here is my code which is only giving me filename I am not getting external url like this
https://4512314-sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=692&deploy=1
here is my code
function searchScriptFile()
{
var folderid = 'SuiteScripts';
var filters = new Array();
filters[0] = new nlobjSearchFilter('name', null, 'is', folderid);
var columns = new Array();
var filename = new nlobjSearchColumn('name', 'file');
var fileid = new nlobjSearchColumn('internalid', 'file');
var path = new nlobjSearchColumn('url', 'file');
columns[0] = filename;
columns[1] = fileid;
columns[2] = path;
var searchResult = nlapiSearchRecord('folder', null , filters , columns);
var res = new Array();
if(searchResult) {
for (var i = 0 ; i < searchResult.length; i++) {
thisfile = searchResult[i].getValue(filename);
thisfileid = searchResult[i].getValue(fileid);
thispath = searchResult[i].getValue(path);
res[i] = thisfile + ' ' + thisfileid + ' ' + thispath;
nlapiLogExecution('DEBUG', 'Test', thisfileid + ' ' + thisfile);
}
return res[27];
}
}
You need to search for the script deployments, not the files in the file cabinet.
var scriptdeploymentSearch = nlapiSearchRecord("scriptdeployment",null,
[
],
[
new nlobjSearchColumn("title").setSort(false),
new nlobjSearchColumn("scriptid"),
new nlobjSearchColumn("script"),
new nlobjSearchColumn("scriptid","script",null),
new nlobjSearchColumn("recordtype"),
new nlobjSearchColumn("status"),
new nlobjSearchColumn("isdeployed"),
new nlobjSearchColumn("scripttype"),
new nlobjSearchColumn("ismobilemenu"),
new nlobjSearchColumn("apiversion","script",null)
]
);
You need to run search on scriptdeployment(as suggested above by dcrs) and not on folder. Although I didn't find any way to fetch externalurl of the script-deployement, guess NetSuite doesn't support it yet.
Here is the basic code to on ScriptDeploymemts though
search.create({
type: 'scriptdeployment',
columns: ['script.scriptfile', 'title',
'scriptid', 'script.apiversion']
}).run().getRange({ start: 0, end: 1000 });
Related
Below code is to select line items for deposit. it saves records to Net suite.But i just want to select line items and that is not happening.
function OnPageInit()
{
var search = nlapiSearchRecord(null, 'customsearch322');
nlapiLogExecution('DEBUG', 'creating a `enter code here`deposit');
var d = nlapiCreateRecord('depo' + 'sit');
d.setFieldValue('department', 13);
d.setFieldValue('trandate', nlapiDateToString(new Date()));
d.setFieldValue('memo', 'created in code');
d.selectNewLineItem('other');
d.setCurrentLineItemValue('other','entity', 41877);
d.setCurrentLineItemValue('other','department', 13);
d.setCurrentLineItemValue('other','account', 135);
d.setCurrentLineItemValue('other','amount',23);
d.setCurrentLineItemValue('other','memo','Tgh');
d.commitLineItem('other');
// iF uncomment tbelow line it save records to Netsuite
//var id = nlapiSubmitRecord(d, true);
}
Below is the correct code
nlapiSelectLineItem("other", 1);
nlapiSetCurrentLineItemValue('other','entity', 41877);
nlapiSetCurrentLineItemValue('other','department', 13);
nlapiSetCurrentLineItemValue('other','account', 135);
nlapiSetCurrentLineItemValue('other','amount', 23);
nlapiSetCurrentLineItemValue('other','memo','Tgh');
nlapiCommitLineItem("other");
This is the working code...........
function clickMe()
{
var transid = nlapiGetFieldValue('custbody2');
var filters = [
new nlobjSearchFilter('transactionnumber', null, 'is', transid),
];
var search = nlapiSearchRecord(null, 'customsearch322',filters);
var k=1;
for(i=0;i<search.length;i++)
{
var CheckaccountId=search[i]["valuesByKey"]["account"]["value"];
var ccode=search[i]["valuesByKey"]["customer_custentity_mb_ccode"]["value"];
var department=search[i]["valuesByKey"]["department"]["value"];
if(CheckaccountId =="1" || CheckaccountId=="7")
{
var setaccount= getaccountforitem(CheckaccountId,ccode,department);
nlapiSelectLineItem("other", k);
k++;
var client =search[i]["valuesByKey"]["customer_internalid"]["value"];
nlapiSetCurrentLineItemValue('other','entity',client);
nlapiSetCurrentLineItemValue('other','department',search[i]["valuesByKey"]["department"]["value"]);
nlapiSetCurrentLineItemValue('other','account', setaccount);
nlapiSetCurrentLineItemValue('other','amount', search[i]["valuesByKey"]["amount"]["value"]);
//nlapiSetCurrentLineItemValue('other','class', search[i]["valuesByKey"]["classnohierarchy"]["value"]);
nlapiSetCurrentLineItemValue('other','memo',search[i]["valuesByKey"]["memo"]["value"]);
nlapiCommitLineItem("other");
}
}
}
I woulld like to create then add 2 files into same file as attachment.
How can i do that? Please find below what i tried so far.
Excel files comes from resource/files and TXT file is just created during document saving progress.
importPackage(org.apache.poi.ss.usermodel);
var resourcePath = "/SampleExcelFile.xlsx";
var bantfile = java.lang.System.getProperty("java.io.tmpdir");
var srtEk = "FileName1";
var excelName = srtEk + ".xlsx";
var textFileName = srtEk + +".txt";
var excelFilePath = bantfile+"\\"+ excelName;
var ledesFilePath = bantfile+"\\"+ textFileName;
var inp = facesContext.getExternalContext().getResourceAsStream(resourcePath);
var wb = WorkbookFactory.create(inp);
var sheet = wb.getSheetAt(0);
var row = sheet.getRow(2);
if (row == null)
{
row = sheet.createRow(2);
}
var cell = row.getCell(0);
if (cell == null)
{
cell = row.createCell(0);
}
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue(tempFilePath);
var fileOut = new java.io.FileOutputStream(excelFilePath);
wb.write(fileOut);
fileOut.close();
var fileOut = new java.io.FileOutputStream(ledesFilePath);
wb.write(fileOut);
fileOut.close();
var doc = database.createDocument();
doc.replaceItemValue("Form", "frmTest");
var rtitem = doc.createRichTextItem("Body");
rtitem.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT, null, excelFilePath , null);
doc.save(true, false);
You can add as much attachments to a RichText field as you like.
Just add another embedObject line to your code:
rtitem.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT, null, ledesFilePath, null);
When using adhoc nlapiSearchRecord within scripts, such as:
var filters = new Array();
var columns = new Array();
filters[0] = new nlobjSearchFilter('isinactive', null, 'is', 'F' );
filters[1] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0);
filters[2] = new nlobjSearchFilter('internalid', 'vendor', 'anyof', vendorid );
columns[0] = new nlobjSearchColumn('itemid');
columns[1] = new nlobjSearchColumn('entityid', 'vendor');
columns[2] = new nlobjSearchColumn('vendorcode');
columns[3] = new nlobjSearchColumn('formulanumeric');
columns[3].setFormula('{vendorcost}');
columns[4] = new nlobjSearchColumn('vendorpricecurrency');
columns[5] = new nlobjSearchColumn('isinactive');
columns[6] = new nlobjSearchColumn('vendor');
columns[7] = new nlobjSearchColumn('averagecost');
columns[8] = new nlobjSearchColumn('lastpurchaseprice');
columns[9] = new nlobjSearchColumn('custitem_costrepl');
var searchresults = nlapiSearchRecord('item', null, filters, columns );
How do I retrieve the value of the formula in column 3?
I've tried searchresults.getValue(column[3])) and searchresults.getValue(3)) but both fail.
The reason for this, is some of our vendorcost values are 4 or 5 decimal places, but the most decimal precision the plain search returns is 3.
You are ignoring the fact that searchResults is an array
And there are multiple ways:
Option#1 //works always
searchresults[INDEX].getValue(searchresults[INDEX].getAllColumns()[3]);
Option#2 //works always - same as what you tried, but, you missed array
searchresults[i].getValue(columns[3]);
Option#3 //use only if you have one numeric formula
searchresults[INDEX].getValue('formulanumeric');
var filters = new Array();
filters[0] = new nlobjSearchFilter('isinactive', null, 'is', 'F');
filters[1] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0);
filters[2] = new nlobjSearchFilter('internalid', 'vendor', 'anyof', vendorid);
var columns = new Array();
columns[0] = new nlobjSearchColumn('itemid');
columns[1] = new nlobjSearchColumn('entityid', 'vendor');
columns[2] = new nlobjSearchColumn('vendorcode');
columns[3] = new nlobjSearchColumn('formulanumeric').setFormula('{vendorcost}'); // you can use formula inline
columns[4] = new nlobjSearchColumn('vendorpricecurrency');
columns[5] = new nlobjSearchColumn('isinactive');
columns[6] = new nlobjSearchColumn('vendor');
columns[7] = new nlobjSearchColumn('averagecost');
columns[8] = new nlobjSearchColumn('lastpurchaseprice');
columns[9] = new nlobjSearchColumn('custitem_costrepl');
var searchresults = nlapiSearchRecord('item', null, filters, columns);
for (var i = 0; searchresults != null && i < searchresults.length; i++) {
var vendorcost = searchresults[i].getValue(columns[3]); // gives you the formula field value
}
Re-entering the code as follows, with combined suggestions from #bknights & #prasun
function main_GetVendorItems(request, response) {
response.write(JSON.stringify(getVendorItems(request)));
}
function getVendorItems(request) {
var vendorid = request.getParameter('vendor');
nlapiLogExecution('DEBUG', 'searchRes', 'Searching For Vendor ID: '+vendorid );
var filters = new Array();
var columns = new Array();
filters[0] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0);
filters[1] = new nlobjSearchFilter('othervendor', null, 'is', [vendorid] );
columns[0] = new nlobjSearchColumn('itemid');
columns[1] = new nlobjSearchColumn('entityid', 'vendor');
columns[2] = new nlobjSearchColumn('vendorcost');
columns[3] = new nlobjSearchColumn('vendorcode');
columns[4] = new nlobjSearchColumn('vendorpricecurrency');
var searchresults = nlapiSearchRecord('item', null, filters, columns );
//for test test each element of the array
(searchresults || []).forEach(function(res){
nlapiLogExecution('DEBUG', 'searchRes', res instanceof nlobjSearchResult);
})
return searchresults;
}
The calling function as below:
function test () {
var vendorID = nlapiGetFieldValue('custrecordvpr_supplier'); alert('searching for vendor ID: '+vendorID );
var url = nlapiResolveURL('SUITELET', 'customscriptls_getvendoritems', 'customdeployls_getvendoritems', true);
var params = {}
params['vendor'] = vendorID;
var response = nlapiRequestURL(url, params);
var VendorItemsSublist = response.getBody();
nlapiSetFieldValue('custrecordvpr_comment',VendorItemsSublist );
}
I've got a comment field on my custom record/form which shows the returned object. On the code above, what's really strange, is I'm not getting any information being added to the execution log,even the first entry where it should post the vendor id being searched for.
I've checked the script and deployment records, and there is nothing untoward or amiss there... I have got to be missing something extremely simple.
Incidentally, the code is being called by a "Test" button on my custom form.
It looks like you are not writing properly to the response object in Suitelet.
function main_GetVendorItems(request, response) {
response.write(JSON.stringify(getVendorItems(request)));
}
function getVendorItems(request) {
var vendorid = request.getParameter('vendorid');
var filters = new Array();
var columns = new Array();
filters[0] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0);
//filter should be on vendor
filters[1] = new nlobjSearchFilter('vendor', null, 'anyof', vendorid );
columns[0] = new nlobjSearchColumn('itemid');
columns[1] = new nlobjSearchColumn('entityid', 'vendor');
columns[2] = new nlobjSearchColumn('vendorcost');
columns[3] = new nlobjSearchColumn('vendorcode');
columns[4] = new nlobjSearchColumn('vendorpricecurrency');
var searchresults = nlapiSearchRecord('item', null, filters, columns );
//for test test each element of the array
(searchresults || []).forEach(function(res){
nlapiLogExecution('DEBUG', 'searchRes', res instanceof nlobjSearchResult);
})
return searchresults;
}
Also, make sure vendor id is specified in request parameter
var url = nlapiResolveURL('SUITELET', 'customscriptls_getitemvendors', 'customdeploy_getitemvendors', true);
var params = {}
params['itemid'] = itemID ; // itemID is passed to this function.
params['vendorid'] = vendorID ; // vendorID is passed to this function.
var response = nlapiRequestURL(url, params);
var itemVendorSublist = response.getBody();
If you're trying to query on item vendor then simply try
filters[1] = new nlobjSearchFilter('vendor', null,'anyof', vendorid );
This works in a console window. I suspect you are not supplying the numeric internal id in your parameter:
var vendorid = 43; // or 32 values from my test account. Want to confirm that the code works whether vendor is item's preferred vendor or not.
nlapiSearchRecord('item', null, [
new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0),
new nlobjSearchFilter('internalid', 'vendor', 'anyof', [vendorid]), //numeric value
new nlobjSearchFilter('internalid', null, 'is', '42') // limit results for testing
], [
new nlobjSearchColumn('itemid'),
new nlobjSearchColumn('entityid', 'vendor'),
new nlobjSearchColumn('vendorcost'),
new nlobjSearchColumn('vendorcode'),
new nlobjSearchColumn('vendorpricecurrency')
]).forEach(function(it) {
console.log("%s from %s", it.getValue('itemid'), it.getValue('entityid', 'vendor'));
});
Although I've been working with Netsuite since 2002 I've never returned a set of search results directly from a Suitelet. I've seen that a couple of times recently in people's answers on this forum but I still find it a bit amusing.
If I were writing this I'd have tended to do the following:
var results = (nlapiSearchRecord(...) || []).map(function(res){
return { id:res.getId(), vendorName: res.getValue('entityid', 'vendor')...};
});
response.setContentType('JAVASCRIPT');
response.write(JSON.stringify(results));
Actually there's generally a little more. I have a sublime text snippet that I use for suitelet responses that handles a couple of common JSONP patterns (e.g. if you were calling this from a website):
function _sendJSResponse(request, response, respObject){
response.setContentType('JAVASCRIPT');
var callbackFcn = request.getParameter("jsoncallback") || request.getParameter('callback');
if(callbackFcn){
response.writeLine( callbackFcn + "(" + JSON.stringify(respObject) + ");");
}else response.writeLine( JSON.stringify(respObject) );
}
Suppose I have 2 Lists: Teams and Employees. Each team has a number of employees:
Teams
ID
Name
Employees
ID
Name
TeamID (foreign key of Teams)
Is it possible to write a query in SharePoint JSOM such that I could do something along the following lines (after the query executes/loads):
var employeesListItems = teamListItem.get_item("Employees")
Does SharePoint Object Model support this in any way?
Clarification: my intent is to reuse the ClientObject as much as I can. I understand that I could query for all employees and all teams, create an array of custom objects for each, and then iterate over employees and push them to onto the "Employees" field of the related Team object. I would like to avoid doing so.
Even though SharePoint CAML supports List Joins and Projections, in that case I would suggest you a different approach.
The following example demonstrates how to retrieve parent/child items using a single request:
function getItemWithDetails(parentListTitle,childListTitle,lookupFieldName,lookupFieldValue,success,error)
{
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var lists = web.get_lists();
var parentList = lists.getByTitle(parentListTitle);
var parentItem = parentList.getItemById(lookupFieldValue);
var childList = lists.getByTitle(childListTitle);
var childItems = childList.getItems(createLookupQuery(lookupFieldName,lookupFieldValue));
ctx.load(parentItem);
ctx.load(childItems);
ctx.executeQueryAsync(
function() {
success(parentItem,childItems);
},
error
);
}
function createLookupQuery(lookFieldName,lookupFieldValue)
{
var queryText =
"<View>" +
"<Query>" +
"<Where>" +
"<Eq>" +
"<FieldRef Name='{0}' LookupId='TRUE'/>" +
"<Value Type='Lookup'>{1}</Value>" +
"</Eq>" +
"</Where>" +
"</Query>" +
"</View>";
var qry = new SP.CamlQuery();
qry.set_viewXml(String.format(queryText,lookFieldName,lookupFieldValue));
return qry;
}
Usage
var parentListTitle = 'Teams';
var childListTitle = 'Employees'
var lookupFieldValue = 1;
var lookupFieldName = 'Team';
getItemWithDetails(parentListTitle,childListTitle,lookupFieldName,lookupFieldValue,
function(teamItem,employeeItems){
//print parent item
console.log(teamItem.get_item('Title'));
//print child items
for(var i = 0; i < employeeItems.get_count(); i++){
var employeeItem = employeeItems.getItemAtIndex(i);
console.log(employeeItem.get_item('Title'));
}
},
function(sender,args){
console.log(args.get_message());
});
Another option is to utilize List Joins and Projections. The following example demonstrates how to retrieve employee list items with projected team items
function getListItems(listTitle,joinListTitle,joinFieldName,projectedFields,success,error)
{
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getByTitle(listTitle);
var items = list.getItems(createJoinQuery(joinListTitle,joinFieldName,projectedFields));
ctx.load(items);
ctx.executeQueryAsync(
function() {
success(items);
},
error
);
}
function createJoinQuery(joinListTitle,joinFieldName,projectedFields)
{
var queryText =
"<View>" +
"<Query/>" +
"<ProjectedFields>";
for(var idx in projectedFields) {
queryText += String.format("<Field Name='{0}_{1}' Type='Lookup' List='{0}' ShowField='{1}' />",joinListTitle,projectedFields[idx]);
}
queryText +=
"</ProjectedFields>" +
"<Joins>" +
"<Join Type='INNER' ListAlias='{0}'>" +
"<Eq>" +
"<FieldRef Name='{1}' RefType='Id'/>" +
"<FieldRef List='{0}' Name='ID'/>" +
"</Eq>" +
"</Join>" +
"</Joins>" +
"</View>";
var qry = new SP.CamlQuery();
qry.set_viewXml(String.format(queryText,joinListTitle,joinFieldName));
return qry;
}
Usage
var listTitle = 'Employees';
var joinListTitle = 'Teams'
var joinFieldName = 'Team';
var projectedFields = ['ID','Title'];
getListItems(listTitle,joinListTitle,joinFieldName,projectedFields,
function(employeeItems){
//print items
for(var i = 0; i < employeeItems.get_count(); i++){
var employeeItem = employeeItems.getItemAtIndex(i);
var employeeName = employeeItem.get_item('Title');
var teamName = employeeItem.get_item('Teams_Title').get_lookupValue();
console.log(employeeName + ',' + teamName);
}
},
function(sender,args){
console.log(args.get_message());
});
Probably you can not achieve what you want, because of lookup configuration. But you could do the following:
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var lists = web.get_lists();
var teams = lists.getByTitle("Teams");
var employees = lists.getByTitle("Employees");
//just get the first item
var employee = employees.getItemById(1);
ctx.load(employee)
ctx.executeQueryAsync(function() {
var team = employee.get_item("TeamID");
// both the id and the value of the lookup field
var lookupId = team.get_lookupId();
var lookupValue = team.get_lookupValue();
// let's grab all the fields
var fullTeam = teams.getItemById(lookupId)
ctx.load(fullTeam)
ctx.executeQueryAsync({
var name = fullTeam.get_item("Name");
alert("We can get the Name field of the lookup field: " + name);
});
});
I guess, it a bit reverse of what you really intent to achieve but still this way you will exploit CSOM.