how to get data or record from sublist in netsuite using suitlets version 1.0 - suitescript

I have created one form in that am getting data only header parts but m not getting data from subsist record please help me. I have used so many APIs but trying to get stored record type.

From testing, the sublist structure in POST data is stored in the request parameters:
var sublistId = 'insertsublistid';
var valuesParam = sublistId + 'data';
var fieldsParam = sublistId + 'fields';
The data are delimited by the following characters:
var SUBLIST_FIELD_DELIM = /\u0001/;
var SUBLIST_LINE_DELIM = /\u0002/;

This is for SS 2.0
var value = context.request.getSublistValue({
group: 'item',
name: 'amount',
line: '2'
});
See /app/help/helpcenter.nl?fid=section_4314828231.html

Related

Read Data from Firebase to Sheets

I'm having trouble splitting the data once I have retrieved it using .getData().
The firebase data is in the form:
mainTag: subTag1:"["Test1",70,0,18]", subTag2:"["Test2",65,2,18]", etc...
This is as far as I've managed to get as I'm not sure of the format of the data. I can't directly set it to the value of a single cell or a range of cells because the parameters don't match the method signature for the sheet. I've tried splitting the data as if it were an object and as if it were a string but keep getting nulls logged in the logger so I'm not sure what to do with it.
function getData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("TestSheet");
var range = sheet.getRange("A1:D2");
var firebaseUrl = "https://.....firebaseio.com/";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl);
var data = base.getData("mainTag");
//range.setValues(data);
Logger.log(data);
Logs: {subTag2=["Test2",65,2,18], subTag1=["Test1",70,0,18]}
}
My objective is to set the value of 4 cells in a row to the data inside each subtag. (A1="Test1", B1=70, C1=0, D1=18) Then subtag2 is in row 2 and so on. I haven't got to splitting the data yet as I'm not sure how to format the data from firebase for it to be able to be used in .setValues()
You need to loop through the subtags and access the values belonging to each key
This can be best achieved with Object.keys().
Sample:
var data = base.getData("mainTag");
var array = [];
for(var i in data) {
var newdata = Object.keys(data[i]).map(function (key) {
return data[i][key];
});
array.push(newdata);
}
var range = sheet.getRange(1,1, array.length, array[0].length);
range.setValues(array);

discord.js rank command for #user

My rank command is working fine, iv been trying to add the ability to !rank #user. As you can see i have code there to grab the mentioned user, so it will display the mentioned users name and profile pic but my points (because they are requested from message.author) I'm just unsure how i should get the points from the database for the mentioned user. Any help or advice would be amazing, thanks!
(my database is SQLite)
const member = message.mentions.members.first() || message.member || message.guild.members.cache.get(args[0])
score = bot.getScore.get(message.author.id, message.guild.id);
if (!score) {
score = {
id: `${message.guild.id}-${message.author.id}`,
user: message.author.id,
guild: message.guild.id,
points: 0,
level: 1,
};
}
let curxp = score.points;
let curlvl = score.level;
let nxtLvlXp = curlvl * 300;
let difference = nxtLvlXp - curxp;
const embed = new Discord.RichEmbed()
.setTitle("XP / LEVEL")
.setDescription(member.user.tag)
.setThumbnail(member.user.displayAvatarURL)
.setColor(cyan)
.addField('**' + "Level" + '**', curlvl, true)
.addField('**' + "XP" + '**', curxp, true)
.setFooter(`${difference} XP til next level up`, bot.user.displayAvatarURL);
return message.channel.send({ embed });
You pretty much already have it
Instead of using message.author.id for the first argument why not just use the member variable which gives the final member?
Also you should have message.guild.members.cache.get(args[0]) before message.member, since message.member will always exist unless in a DM Channel.
const member = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.member;
score = bot.getScore.get(member.id, message.guild.id);

How to separate multiple columns from a range in an array?

I have a range of data in a Google Sheet and I want to store that data into an array using the app script. At the moment I can bring in the data easily enough and put it into an array with this code:
var sheetData = sheet.getSheetByName('Fruit').getRange('A1:C2').getValues()
However, this puts each row into an array. For example, [[Apple,Red,Round],[Banana,Yellow,Long]].
How can I arrange the array by columns so it would look: [[Apple,Banana],[Red,Yellow],[Round,Long]].
Thanks.
It looks like you have to transpose the array. You can create a function
function transpose(data) {
return (data[0] || []).map (function (col , colIndex) {
return data.map (function (row) {
return row[colIndex];
});
});
}
and then pass the values obtained by .getValues() to that function..
var sheetData = transpose(sheet.getSheetByName('Fruit').getRange('A1:C2').getValues())
and check the log. See if that works for you?
Use the Google Sheets API, which allows you to specify the primary dimension of the response. To do so, first you must enable the API and the advanced service
To acquire values most efficiently, use the spreadsheets.values endpoints, either get or batchGet as appropriate. You are able to supply optional arguments to both calls, and one of which controls the orientation of the response:
const wb = SpreadsheetApp.getActive();
const valService = Sheets.Spreadsheets.Values;
const asColumn2D = { majorDimension: SpreadsheetApp.Dimension.COLUMNS };
const asRow2D = { majorDimension: SpreadsheetApp.Dimension.ROWS }; // this is the default
var sheet = wb.getSheetByName("some name");
var rgPrefix = "'" + sheet.getName() + "'!";
// spreadsheetId, range string, {optional arguments}
var single = valService.get(wb.getId(), rgPrefix + "A1:C30");
var singleAsCols = valService.get(wb.getId(), rgPrefix + "A1:C30", asColumn2D);
// spreadsheetId, {other arguments}
var batchAsCols = valService.batchGet(wb.getId(), {
ranges: [
rgPrefix + "A1:C30",
rgPrefix + "J8",
...
],
majorDimension: SpreadsheetApp.Dimension.COLUMNS
});
console.log({rowResp: single, colResp: singleAsCols, batchResponse: batchAsCols});
The reply will either be a ValueRange (using get) or an object wrapping several ValueRanges (if using batchGet). You can access the data (if any was present) at the ValueRange's values property. Note that trailing blanks are omitted.
You can find more information in the Sheets API documentation, and other relevant Stack Overflow questions such as this one.

$.grep on JSON data in multiple array.fields using wildcards?

First off I have looked through similar looking questions but have not found the exact problem asked or answered, so here goes :
I have a JSON Object which consists of about 900+ posts. Looking like this:
var JsonData = [{"rowNumber":563663,"hasWarning":true,"isInvoiceAccount":true,"phone":"","name":"Romerike AS","address1":"Co/Skanning","address2":"PB 52","attention":"","mobile":"","email":"fakt#bos.no","fax":"","zipCity":"N-1471 Askim","invoiceAccount":"","notes":null,"account":"3","country":"NORGE","salesRep":"4","countryCode":"no"},{"rowNumber":563674,"hasWarning":false,"isInvoiceAccount":true,"phone":"","name":"LILLEHAMMER","address1":"POSTBOKS 110","address2":"","attention":"","mobile":"","email":"","fax":"","zipCity":"N-2605 LILLEHAMMER","invoiceAccount":"","notes":null,"account":"14","country":"NORGE","salesRep":"4","countryCode":"no"},{"rowNumber":563676,"hasWarning":true,"isInvoiceAccount":true,"phone":"63929788","name":"Askim Bil AS","address1":"Postboks 82","address2":"","attention":"","mobile":"","email":"karosseri#nyg.no","fax":"","zipCity":"N-2051 Askim","invoiceAccount":"","notes":null,"account":"16","country":"NORGE","salesRep":"4","countryCode":"no"},{"rowNumber":563686,"hasWarning":false,"isInvoiceAccount":true,"phone":"69826060","name":"KAROSSERI A/S","address1":"POSTBOKS 165","address2":"","attention":"","mobile":"","email":"tkar#online.no","fax":"","zipCity":"N-1860 TRØGSTAD","invoiceAccount":"","notes":null,"account":"26","country":"NORGE","salesRep":"4","countryCode":"no"},{"rowNumber":563690,"hasWarning":false,"isInvoiceAccount":true,"phone":"","name":"AUTOSERVICE A/S","address1":"POSTBOKS 15","address2":"","attention":"","mobile":"","email":"","fax":"","zipCity":"N-2851 LENA","invoiceAccount":"","notes":null,"account":"30","country":"NORGE","salesRep":"4","countryCode":"no"},{"rowNumber":563691,"hasWarning":false,"isInvoiceAccount":false,"phone":"","name":"ØYHUS A/S","address1":"POSTBOKS 321","address2":"","attention":"John Doe","mobile":"","email":"","fax":"","zipCity":"N-2817 GJØVIK","invoiceAccount":"","notes":null,"account":"31","country":"NORGE","salesRep":"4","countryCode":"no"}];
I want to filter these data before I read them into a table using $.grep.
The JSON data have been loaded as an object.
In the HTML page I have a textfield named "filter".
The following code works, but only when I search for an exact match:
var JsonFiltered = $.grep(JsonData, function (element, index) {
return element.zipCity == $('#filter').val();
});
$.each( JsonFiltered, function ( index, value ) {
// sorting through the array adding values to a table
[...]
});
Problem 1:
I want to use Wildcards when filtering.
I read something about using regexp but I haven't found any viable examples.
Problem 2:
I want to be able to filter more than one column.
Example: filtering the word "Askim" in both element.name and element.zipCity
So I figured out the solutions myself...
Using Wildcards:
var search_term = $('#filter').val();
var search = new RegExp(search_term, "i");
var JsonFiltered = $.grep(JsonTest, function (element, index) {
var zipC = search.test(element.zipCity)
var names = search.test(element.name)
return zipC + names ;
The solution was to use "new RegExp" with the filter "i" setting.
then I took two search.tests combined them in the return command and... presto
Hope this helps anyone else.

How to apply segment using Google Analytics .NET client

I am trying to apply a segment for a query through Google Analytics .NET client but I am not able to get it working. Here is what I have been trying:
var segments = analyticsService.Management.Segments.List().Execute();
var engagedTeamsSegment = segments.Items.FirstOrDefault(x => x.Name.Equals("Engaged Teams", StringComparison.OrdinalIgnoreCase));
var format = "yyyy-MM-dd";
var today = DateTime.UtcNow.Date;
var thirtyDaysAgo = today.Subtract(TimeSpan.FromDays(30));
var metrics = engagedTeamsSegment.Definition.Replace(';', ',');
var gaData = analyticsService
.Data.Ga
.Get($"ga:{profile.Id}", today.ToString(format), thirtyDaysAgo.ToString(format), metrics)
.Execute();
It's getting me the below error
An unhandled exception of type 'Google.GoogleApiException' occurred in
Google.Apis.dll
Additional information: Google.Apis.Requests.RequestError
Invalid value
'users::condition::ga:dimension2!=0,ga:sessionCount>=2,ga:daysSinceLastSession<=14'.
Values must match the following regular expression: 'ga:.+' [400]
Errors [
Message[Invalid value
'users::condition::ga:dimension2!=0,ga:sessionCount>=2,ga:daysSinceLastSession<=14'.
Values must match the following regular expression: 'ga:.+']
Location[metrics - parameter] Reason[invalidParameter] Domain[global]
]
I am probably doing something wrong but not sure what. Any ideas?
Found the solution thanks to this question. There was a Segment parameter on the request. Below code did the trick:
var segments = analyticsService.Management.Segments.List().Execute();
var engagedTeamsSegment = segments.Items.FirstOrDefault(x => x.Name.Equals("Engaged Teams", StringComparison.OrdinalIgnoreCase));
var format = "yyyy-MM-dd";
var today = DateTime.UtcNow.Date;
var thirtyDaysAgo = today.Subtract(TimeSpan.FromDays(30));
var gaDataRequest = analyticsService
.Data.Ga
.Get($"ga:{profile.Id}", thirtyDaysAgo.ToString(format), today.ToString(format), "ga:users");
gaDataRequest.Segment = engagedTeamsSegment.Definition;
var gaData = gaDataRequest.Execute();

Resources