How can we get the url of any record using TransactionSearchAdvanced using java - suitetalk

I want to get NetSuite URL of a record using saved search in java suite talk
This is a java script code of Transaction Search, I have to convert it into Suite talk using java. I am able to get internalid, account, entity etc but i am not able to get link for each record. How can i get the link?
util.each(searchResults, function (row) {
var obj = {
id: row.internalid,
linkText: row.account,
link: commons.resolveRecordUrl('invoice', row.internalid),
text: ' | ' + row.entity + ' | ' + self.formatMoney(row.amount) + ' | ' + row.trandate
};
// log.debug({ title: "obj", details: obj });
results.push(obj);
});

Related

Why does this work? Spotify API call node.js

I am new to node and am working on an API call via node.js and am kinda confused why this works. I have done other API calls via node with ease as it was easy to figure out how to target the various fields etc.. but I never got a link with the spotify API and am confused how data.tracks.items.artists.name gave me the artist name?
I know this is an ignorant question but I really want to understand how this works not just make it work.
function song() {
var nodeArgs = process.argv;
var SongName = "";
for (var i = 3; i < nodeArgs.length; i++) {
if (i > 3 && i < nodeArgs.length) {
SongName = SongName + "+" + nodeArgs[i];
}
else {
SongName += nodeArgs[i];
}
}
var Spotify = require('node-spotify-api');
var spotify = new Spotify({
id: "id",
secret: "secret"
});
spotify.search({ type: 'track', query: SongName, limit: 1 }, function (err, data) {
if (err) {
SongName = "";
console.log("Artist: " + songData.artists[0].name);
console.log("Song Title: " + songData.name);
console.log("Preview Track: " + songData.preview_url);
console.log("Album: " + songData.album.name);
song();
}
for (var i = 0; i < data.tracks.items.length; i++) {
var songData = data.tracks.items[i];
console.log("Artist: " + songData.artists[0].name);
console.log("Song Title: " + songData.name);
console.log("Preview Track: " + songData.preview_url);
console.log("Album: " + songData.album.name);
}
});
}
Short Answer -
the track api endpoint responds with the Object Model which also contains artist objects - which is an array of artist objects, where the artist object contains the key name.
ref: https://developer.spotify.com/documentation/web-api/reference/tracks/get-track/
From their API docs
GET https://api.spotify.com/v1/tracks/{id}
the response object contains
KEY VALUE | TYPE | VALUE DESCRIPTION
---
artists | an array of simplified | The artists who performed the track.
| artist objects | information about the artist.
Artist Object
artist object (simplified)
KEY VALUE | TYPE | VALUE DESCRIPTION
---
external_urls | an external URL object | Known external URLs for this artist.
href | string | A link to the Web API endpoint providing full details of the artist.
id | string | The Spotify ID for the artist.
name | string | The name of the artist
type | string | The object type: "artist"
uri | string | The Spotify URI for the artist.

Using SuiteScript to populate a transfer order

Current issue is that i can't commit a line item. Do i need to add more fields even though item is the only one required?
function OLDcreateTO() //(request, response)
{
for ( var i = 1; i < lines + 1 ; i++ )
{
nlapiLogExecution('DEBUG','<Before Load Script> type: '+type,"line # " + i);
arrayName[i] = PORecord.getLineItemValue('item', 'item', i );
nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, arrayName[i]);
}
nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, lines + ' lines');
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);
nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'break 4');
// add new lines to a sublist
nlapiSelectNewLineItem('item');
// set the item and location values on the currently selected line
nlapiSetCurrentLineItemValue('item', 'item', arrayName[1]);
nlapiSetCurrentLineItemValue('item', 'location', 6);
// commit the line to the database
nlapiCommitLineItem('item');
nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'break 5');
var TOResult = nlapiSubmitRecord(TOrecord, true, true);
var TOTranID= nlapiLookupField('transferorder', TOResult, 'tranid');
nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'break 6');
var poURL = nlapiResolveURL('RECORD', 'transferorder', TOResult);
nlapiSetRedirectURL('RECORD','transferorder', TOResult);
}
So I am trying to have the items of a purchase order populate the items field on a new transfer order via a button on the PO. From there the user can make any changes they want to the record before submitting it and creating the TO. The main issue is I don't know how to populate a blank TO from script. I have it redirect there via a url string, but I'm sure there is a better way to do it.
In summary.
-User clicks "create TO" button on a PO
-takes user to the "create TO" page where all the items (and some various info) is pre populated depending on the PO.
-User edits the record and then submits it.
suitescript 1.0
//create_to_button
var newId ;
var newType ;
function beforeload(type)
{
if(nlapiGetContext().getRole() == '3')
{
if(type =='view' || type == 'edit')
{
newId = nlapiGetRecordId();
newType = nlapiGetRecordType();
if(newType == 'purchaseorder')
{
var strURL = "https://system.na2.netsuite.com/app/accounting/transactions/trnfrord.nl"
var scriptbutton = 'window.open(' + String.fromCharCode(39) + strURL + String.fromCharCode(39) + ')' ;
//nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'URL: '+strURL + '&id=' + newId);
form.addButton('custpage_createpo', 'Create TO', scriptbutton);
}
}
}
}
function loadTO() //(request, response)
{
nlapiLogExecution('DEBUG','<Before Load Script> type: '+type, 'hello');
nlapiLoadRecord(newType, newId);
}
Any ideas or advice is appreciated.
-Brandon
If you know the TO will be saved you would open a Suitelet that will populate the TO. Save it and redirect to the new TO using nlapiSetRedirect with a url from nlapiResolveURL.
If the TO might not be saved then add some parameters to the tasklink url that you are already using and add your population logic to the TO's client side init function. You may need to add some custom fields to the TO with a beforeLoad user event script to provide the info the client script needs. (Your client script can look at query string parameters too but depending on what you are doing the server side lookups may be faster).

How to get a list of internal id in netsuite

Is there a proper way to get a list of all internal id in a Netsuite Record?
var record = nlapiLoadRecord('customer', 1249);
var string = JSON.stringify(record);
nlapiLogExecution('DEBUG', 'string ', string );
I can get most of the id using json string but i am looking for a proper way. It prints all the data including internal id. Is there any Api or any other way ?
I actually developed a Chrome extension that displays this information in a convenient pop-up.
I ran into the same issue of nlobjRecord not stringifying properly, and what I ended up doing was manually requesting and parsing the same AJAX page NS uses internally when you call nlapiLoadRecord()
var id = nlapiGetRecordId();
var type = nlapiGetRecordType();
var url = '/app/common/scripting/nlapihandler.nl';
var payload = '<nlapiRequest type="nlapiLoadRecord" id="' + id + '" recordType="' + type + '"/>';
var response = nlapiRequestURL(url, payload);
nlapiLogExecution('debug', response.getBody());
You can have a look at the full source code on GitHub
https://github.com/michoelchaikin/netsuite-field-explorer/
The getAllFields() function will return an array of all field names, standard and custom, for a given record.
var customer = nlapiLoadRecord('customer', 5069);
var fields = customer.getAllFields();
fields.forEach(function(field) {
nlapiLogExecution('debug', field);
})

NetSuite: Custom Address Fields when Line Item Shipping (MSR) is Enabled

I have a quirky issue with NetSuite. On a Sales Order which has 'Enable Line Item Shipping' checked, meaning Multiple Shipping Routes are Enabled, the shipping address goes on the item line level.
via SuiteScript, I can access the address on the line level IF it is selected from the address book.
However, when that address is a custom address that is entered on the fly, I have no idea how to get to those fields in a beforeSubmit function.
Any pointers would be much appreciated!
You can get the selected address details using either or below two
nlapiGetLineItemValue('item','shipaddress',1)
nlapiGetLineItemText('item','shipaddress',1)
The above would only give you the id, or label of address record. But, would be hard to access the address details on the client side.
However, using sub record APIs you can access the record on server-side in user event script using sub record APIs:
var record = nlapiLoadRecord('customer', nlapiGetFieldValue('entity'),{recordmode: 'dynamic'});
//loop through all the addressbooks
if(record.getLineItemValue('addressbook', 'internalid', i) === nlapiGetLineItemValue('item','shipaddress', 1))
record.selectLineItem('addressbook', 2);
//change the sub record value
var subrecord = record.editCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
subrecord.setFieldValue('attention', 'Accounts Payable');
subrecord.commit();
record.commitLineItem('addressbook');
var x = nlapiSubmitRecord(record);
Figured it out! For those lost souls who venture here in the future:
Below is a function you can use on a sales order line level to loop through the custom addresses and pull out specific information.
Hopefully, this will be added to the NetSuite documentation at some point.
Note that I was doing this specifically for the state information. If you want to see what other fields are available, add &xml=T to the end of a submitted sales order URL and search for iladdrbook in the resuling xml structure. It is actually treated like a line item.
function getCustomAddressFromLineItem(soLineNum) {
nlapiLogExecution('DEBUG', 'Custom Address', 'Custom Address: Line # ' + soLineNum);
var addressid = nlapiGetLineItemValue('item','shipaddress',soLineNum); // get the id of the custom address
var customAddressesLineCount = nlapiGetLineItemCount('iladdrbook'); // get custom address book count
nlapiLogExecution('debug', 'test', 'addressid: ' + addressid + ' -- linecount: ' + customAddressesLineCount);
for (var i = 1; i <=customAddressesLineCount; i++)
{
var addressinternalid = nlapiGetLineItemValue('iladdrbook','iladdrinternalid',i); // get internal id of custom address book
if (addressinternalid == addressid) // match it with the id of custom address being set
{
var addr = nlapiGetLineItemValue('iladdrbook','iladdrshipaddr1',i);
var customState = nlapiGetLineItemValue('iladdrbook','iladdrshipstate',i); // get your state
nlapiLogExecution('debug', 'test', 'address: ' + addr + ' -- state: ' + customState);
return customState;
}
}
}

EndlessScroll using KendoUI Mobile + Azure Mobile Services + SQL Azure

I have been struggling for the past few days with Endless Scrolling on a mobile listview. I have set up my datasource and listview as the demo suggests. I have not been able to successfully get it to work (or 'press to load more' for that matter) on server-side data. The local data works as expected. I have used many different KendoUI core builds and the results are pretty much the same.
One difference I did notice though, is the type: "odata" part in the demo that refuses to work for me (500 Internal Server Error). I therefore tried a normal "GET" type on the datasource. The "GET" was odata-style (https://myserviceapi.azure-mobile.net/tables/EventTypes?$filter=businessID%20eq%2053) which is supported out of the box on Azure Tables, but endless scrolling did not work. I also tried a normal "GET" of an Azure Mobile Services api method that is basically a RESTful method that returns the same data as the odata table query in SQL Azure. None of the things I have tried work. The following code is what I have and tested with many Kendo UI Core builds.
App JavaScript:
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: 'https://myserviceapi.azure-mobile.net/tables/EventTypes?$filter=businessID%20eq%20' + busID,
dataType: "json"
}
},
serverPaging: true,
pageSize: 12
});
$("#photoHolder").kendoMobileListView({
dataSource: dataSource,
template: "<p>#: eventName #</p>",
endlessScrolling: true,
filterable:{
field: "eventName",
operator: "contains",
ignoreCase: true,
placeholder: "search products..."
}
});
HTML:
<ul id="photoHolder" data-role="listview">
</ul>
Azure JavaScript:
exports.get = function(request, response) {
var mssql = request.service.mssql;
var cnt = request.query.pageSize;
var pnm = request.query.page;
var sql = "SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY zOrder) AS RowNum, * FROM myschema.EventTypes where (businessID = " + request.query.busID + ") and active = 1) AS E " +
"WHERE RowNum BETWEEN ((" + pnm + " - 1) * cnt + 1) AND (" + pnm + " * " + cnt + ") ORDER BY zOrder";
mssql.query(sql, {
success: function(results) {
response.send(200, results);
},
error: function(err) {
console.log(err);
response.send(530, { error: err });
}
});
};
I found the answer to this when I was playing around on my own "pet" app. I just had to make sure that there were enough items in the list to actually give that endless scroll experience. In the Kendo UI forums, they suggest a pageSize of at least 30. {http://docs.telerik.com/kendo-ui/mobile/listview/endless-scrolling}

Resources