Zoho Creator - Retrieving the actual text value of a Form's Lookup Dropdown field - field

I'm following the Zoholics videos on Deluge and used this statement to lookup the pizza price from the Inventory:
colPizzaDetails = Inventory[Pizza == input.Pizza && Size == input.Pizza_Size];
This error is displayed when trying to save the script:
In Criteria left expression is of type STRING and right expression is of type BIGINT and the operator == is not valid
In the video, the narrator was able to save the script. Looks like a BIGINT is stored in the Lookup Dropdown now instead of text as shown in the video.
Can you tell me how to alter the code statement so I can change input.Pizza to represent the actual Pizza Name text that the user sees on the screen?

you should convert the input result to an integer using toNumber() function Like this:
colPizzaDetails = Inventory[Pizza == input.Pizza && Size ==
input.Pizza_Size.toNumber()];

It seams Inventory form is having the Pizza field as a string field.
And in the current form it seams Pizza field is a lookup from Pizza Form.
so whenever you try to access a lookup field , u'll get the Record ID in return, you can check it by logging that using alert or info command , example alert or info (input.Pizza) in u'r current form.
so first u'll need to fetch the pizza name from Pizza Form and then compare it in u'r query.
lets say pizza name field in Pizza Form is Pizza_Name;
so this is how u'r code should look
// fetch pizza_name : make sure you replace Pizza_Name
// by the deluge name of pizza name field in pizza form.
pizza_name = Pizza[ID==input.Pizza].Pizza_Name;
// compare pizza_name with inventory pizza and
// fetch inventory data.
colPizzaDetails = Inventory[Pizza == pizza_name && Size == input.Pizza_Size];
and this should work fine.
OR
you can also try
colPizzaDetails = Inventory[Pizza == input.Pizza.Pizza_Name && Size == input.Pizza_Size];
but that can give you this error in some cases.
Pizza is a lookup field and child fields cannot be accessed
so the First approach will work in all cases & is preferred approach from zoho standard point of view.

Related

How to sort on hidden or data-attribute value in textSorter

I have a "name" column in a table that contains a persons full name (ie. first+last name). The objective is to sort the column based on the person's last name first, then first name. My initial naive approach for the textsorter function was
function (a, b){
const aSplit = a.split(' ');
const bSplit = b.split(' ');
const aReverse = aSplit[1] + aSplit[0];
const bReverse = bSplit[1] + bSplit[0];
return aReverse.localeCompare(bReverse);
}
Unfortunately, some of the names I have to sort have extraneous spaces in them, potentially in either the first name or last name field. So I have to support this in my sorting.
I am currently only using the combined first+last name string for display and sorting but I have access to the seperate name strings as well as a preformatted lastname, firstname version. I'd like to attach either of these to the <th> tags as a data attribute or something like that and sort using that instead of the actual value but I'm not sure how to go about accessing those attributes from within the textsorter function.
Maybe try this - when you build the table HTML, add the last name + first name into a data-text attribute of the cell. Tablesorter will automatically use that attribute over the actual text within the cell. See textAttribute option to allow changing that attribute name.

How do i remove rows based on comma-separated list of values in a Power BI parameter in Power Query?

I have a list of data with a title column (among many other columns) and I have a Power BI parameter that has, for example, a value of "a,b,c". What I want to do is loop through the parameter's values and remove any rows that begin with those characters.
For example:
Title
a
b
c
d
Should become
Title
d
This comma separated list could have one value or it could have twenty. I know that I can turn the parameter into a list by using
parameterList = Text.Split(<parameter-name>,",")
but then I am unsure how to continue to use that to filter on. For one value I would just use
#"Filtered Rows" = Table.SelectRows(#"Table", each Text.StartsWith([key], <value-to-filter-on>))
but that only allows one value.
EDIT: I may have worded my original question poorly. The comma separated values in the parameterList can be any number of characters (e.g.: a,abcd,foo,bar) and I want to see if the value in [key] starts with that string of characters.
Try using List.Contains to check whether the starting character is in the parameter list.
each List.Contains(parameterList, Text.Start([key], 1)
Edit: Since you've changed the requirement, try this:
Table.SelectRows(
#"Table",
(C) => not List.AnyTrue(
List.Transform(
parameterList,
each Text.StartsWith(C[key], _)
)
)
)
For each row, this transforms the parameterList into a list of true/false values by checking if the current key starts with each text string in the list. If any are true, then List.AnyTrue returns true and we choose not to select that row.
Since you want to filter out all the values from the parameter, you can use something like:
= Table.SelectRows(#"Changed Type", each List.Contains(Parameter1,Text.Start([Title],1))=false)
Another way to do this would be to create a custom column in the table, which has the first character of title:
= Table.AddColumn(#"Changed Type", "FirstChar", each Text.Start([Title],1))
and then use this field in the filter step:
= Table.SelectRows(#"Added Custom", each List.Contains(Parameter1,[FirstChar])=false)
I tested this with a small sample set and it seems to be running fine. You can test both and see if it helps with the performance. If you are still facing performance issues, it would probably be easier if you can share the pbix file.
This seems to work fairly well:
= List.Select(Source[Title], each Text.Contains(Parameter1,Text.Start(_,1))=false)
Replace Source with the name of your table and Parameter1 with the name of your Parameter.

How to print correlating index number in an array based on user input

I am new to coding, started learning Ruby arrays this week. I am a bit stuck on this problem that asks:
Create a program that asks a user to enter four different words, one at a time. Then, the computer will ask the user to choose a number between 0 and 3. The computer will then display the word corresponding to the correct number:
array = ["response_zero", "response_one", "response_two", "response_three"]
puts "Welcome! Enter 4 words, one at a time:"
times do
response = gets.chomp
end
puts "Now, guess a number between 0 and 3."
response = gets.chomp
** stuck right here on how to get the users entered number to print out the correlating array index. My professor hinted at only needing one line of code below the second response = gets.chomp, but haven't been able to figure it out for the past day.
Any help would be appreciated!
If you want to access an element in array you need to store the value of the input as Integer. So, you need to use the method to_i:
response = gets.chomp.to_i
By default, the gets method takes the user input as a String, so you need to explicitly convert it to Integer.
Now, you can easily access a particular element in the array:
puts "The word is #{array[response]}."
Where array is the name of the array and response is the number that the user entered.
Find more informations here:
class Array
to_i

How to search product data by id and name in one query

I have a index named product in elastic-search with field id, name etc..
I want to search products by id or name but my id field is integer and name is a text, I tried following but getting error while searching by name.
error type":"number_format_exception","reason":"For input string:
\"test\""
def self.search_by_name_or_id(query)
__elasticsearch__.search({
query: {
bool: {
must:{
multi_match: {
query: query,
fields: ["id", "name"]
}
}
}
}
})
end
Problem
Exception is clear, that you are trying to search test which is a String in the integer field and elasticsearch is not able to convert test in integer, instead of test if you had search for 10 or 100, then elasticsearch would convert it into integer and would not throw the exception.
Solution
You are trying to mix 2 things here, I am not sure about your design but if your id field can contain pure numbers i.e. integers, then it's not possible to achieve in a single query the way you are doing.
If you can convert your id field to String, then multi_match query would work perfectly fine, otherwise, you need to first check in your application, that search term can be converted to number or not, i.e. 10 or 100 would work fine but test10 or test100 would not and anyway there is no point of searching these terms in id field as it won't be present as its defined as integer in ES and ES would reject documents containing these terms during indexing time only. So based on your application code check you can construct the ES query which may or may not include the id field in multi-match.

InfluxDB design issue

I am using influxDB and using line protocol to insert large set of data into Data base. Data i am getting is in the form of Key value pair, where key is long string contains Hierarchical data and value is simple integer value.
Sample Key Value data :
/path/units/unit/subunits/subunit[name\='NAME1']/memory/chip/application/filter/allocations
value = 500
/path/units/unit/subunits/subunit[name\='NAME2']/memory/chip/application/filter/allocations
value = 100
(Note Name = 2)
/path/units/unit/subunits/subunit[name\='NAME1']/memory/chip/application/filter/free
value = 700
(Note Instead of allocation it is free at the leaf)
/path/units/unit/subunits/subunit[name\='NAME2']/memory/graphics/application/filter/swap
value = 600
Note Instead of chip, graphics is in path)
/path/units/unit/subunits/subunit[name\='NAME2']/harddisk/data/size
value = 400
Note Different path but till subunit it is same
/path/units/unit/subunits/subunit[name\='NAME2']/harddisk/data/free
value=100
Note Same path but last element is different
Below is the line protocol i am using to insert data.
interface, Key= /path/units/unit/subunits/subunit[name\='NAME2']/harddisk/data/free, valueData= 500
I am Using one measurement namely, Interface. And one tag and one field set. But this DB design is causing issue for querying data.
How can I design database so that i can query like, Get all record for subunit where name = Name1 or get all size data for every hard disk.
Thanks in advance.
The Schema I'd recommend would be the following:
interface,filename=/path/units/unit/subunits/subunit[name\='NAME2']/harddisk/data/free value=500
Where filename is a tag and value is the field.
Given that the cardinality of filename in the thousands this schema should work well.

Resources