How to convert custom fields array into the key value pair? - zapier

I have a trigger, which returning ar array of custom fields. each element of the array have a two keys FIELD_VALUE and FIELD_NAME.
When I am mapping these fields in an action there are only two field available :
FIELD VALUES ==> comma separated values of all custom fields key FIELD_VALUE, similarly
FIELD NAMES ==> comma separated values of all custom fields key FIELD_NAMES
I want to convert all of the fields in a key:value pair. So the value of FIELD_NAME will be a key and value of FIELD_VALUE will be a value.
I have tried to use code by zapier but it is not working as expected:
Here is my JS code:
var names = (inputData.names).split(',');
var values = ((inputData.values).toString()).split(',');
var obj = names.reduce((obj, key, index) => ({ ...obj, [key]: values[index] }), {});
The problem is null values, Zapier removing null values from comma separated string.

Related

Sorting rows in a Grid column of String type based on corresponding integer values

I have the following structure for a Grid and wanted to know how to sort a column based on the Integer values of the Strings. The data provider is not flexible to change, so I have to sort with some kind of intermediary step:
Grid<String[]> grid = new Grid<>();
...
grid.addColumn(str -> str[columnIndex]).setHeader("sample").setKey("integercolumn").setSortable(true);
...
GridSortOrder<String> order = new GridSortOrder<>(grid.getColumnByKey("integercolumn"), SortDirection.DESCENDING);
grid.sort(Arrays.asList(order));
This sorts two digit numbers properly but not one digit or 3+.
You can define a custom comparator on the column that is used for sorting its values. In your case the comparator needs to extract the column-specific value from the array, and then convert it to an int:
grid.addColumn(row -> row[columnIndex])
.setHeader("sample")
.setKey("integercolumn")
.setSortable(true)
.setComparator(row -> Integer.parseInt(row[columnIndex]));
See https://vaadin.com/docs/latest/components/grid/#specifying-the-sort-property.

How to insert key and value dynamically in a property list in eggplant

I have fetched a data as list of list (inner list consists of 2 values e.g., (name,sam)) , now I want to read the data of each inner list and add first data as key and add second data as a value of property list .
e.g.,
((name,sam),(date,fourth),(age,twenty)) = list of lists
convert to = (name:"sam",date:"fourth",age:"twenty") = property list
How can i achieve this ?
set excelRead to WorkBook(ResourcePath(fileName))
set readColumns to excelRead.Worksheet(sheetName)
set listOfData to cellRange("A:B") of readColumns
put (:) into newPlist
repeat with each item of listOfData
put item 1 of it into key
put item 2 of it into Value
end repeat
You just need to put brackets around a variable name to use it as the key in a property list:
put Value into newPlist.(key)
put Value into (key) of newPlist
put Value into newPlist's (key)
It's in the SenseTalk Reference here: Referencing Property List Keys Using Variables

Parse tab delimited CSV file to array of hashes in Ruby 2.0

I have the following code:
def csv_to_array(file)
csv = CSV::parse(file)
fields = csv.shift
array = csv.collect { |record| Hash[*fields.zip(record).flatten] }
end
This creates an array of hashes, and works fine with comma separated values. I am trying to replicate this code for a tab delimited file. Currently, when I run the above code on my tab delimited file, I get something like this:
array[0] = {"First Name\tLast Name\tCode\t"=>"Luigi\tSmith\t1406\t"}
So, each array object is a hash as intended, but it has one key value pair - The entire tab delimited header row being the key, and the individual row of data being the value.
How can I alter this code to return an array of hashes with individual key value pairs, with the header of each column mapping to the row value for that column?
It seems that the options you pass to parse are listed in ::new
>> CSV.parse("qwe\tq\twe", col_sep: "\t"){|a| p a}
["qwe", "q", "we"]
Use the col_sep option, this post has the code: Changing field separator/delimiter in exported CSV using Ruby CSV
also checkout the docs: http://ruby-doc.org/stdlib-2.1.0/libdoc/csv/rdoc/CSV.html
lots of good stuff in the DEFAULT_OPTIONS section

Construct a Hash collection that can be sorted by time of insertion

From time to time I'm inserting key-value pairs to a Hash.
How can I construct this Hash such that I can sort the pairs by the Time they were created?
If I create a nested Hash where the key would be a timestamp (in String format I suppose) and the value the value-key pair - would that be "easy" to sort chronologically then or is there any better way?
Hash already behaves like that. Basically, the elements are ordered based on the time you inserted the element.
Hashes enumerate their values in the order that the corresponding keys were inserted.
Source
You can simply set your keys as a timestamps each time you insert a value to your hash.
For ex:
your_hash = {}
unique_timestamp = Time.now.to_s #time key as a string (you can create it each time
#you want to insert a value)
your_hash[unique_timestamp] = "new_value"
So, you can inspect your hash like "your_hash.inspect" and you will see your key as a string timestamp format and then your value.

Parse the xml store the values in HashMap.Attribute name as key and attribute value as value.

Parse the below xml and store the values in HashMap.Attribute name should be key and attribute value should be value.
List item

Resources