Error when using Java Functions
Many times when I try to use a Java function in a calculation field on an @All of Item I get the following error:
Preview: Script error: TypeError: undefined is not a function
Some examples:
var Item = @All of item.subString(0,1); // Generates the error
var Item = @All of item.split(","); // Generates the error
var Item = @All of item.sort(); // Does NOT generate the error
I can't figure out what is causing this. Are the functions generating the error not usable in Podio?
Any ideas?
Help is much appreciated!
-
Hi Brett,
all these functions are usable in Podio calculations. But you have to use them in the rigth way :)
With @all of item you get an array of items. So functions for strings couldn't work till you make the array to a string like
@all of item.join().substring(0,1) - and be careful, these functions a case sensitive "subString" would fail.Same with split() which splits a string into an array of substrings: first make the array to a string: var a = @all of item.join(), than split (and you'll get arrays) and back to string : a.split(" ").join() . Or if you would like to get e.g. the third character or word or whatever of the array generated by split(): var b = a.split(" "), var c = b[2]
Normally you would also need .join() for showing the result of .sort(). So if there should occur problems use: @all of item.sort().join().
Rainer
-
Thank you for the quick and thorough reply!
What if @all of item is made up of strings which themselves contain spaces and commas. For example:
if all of item[1] = a, b, c
and
all of item[2] = d, e, fIs it possible to sort them? It seems that once you join them into one string, you have not meaningful way of keeping the "a, b, c" separate from the "d, e, f" based on commas or spaces. Is there another method one would use?
The big picture is I'm trying to make a calculation field where I can see related items with their status and then be able to sort them by status. What I found was that when I sorted the @all of item, the items were sorted, but their corresponding statuses didn't change. I understand why that would be because @all of item and @all of status are different arrays, so to achieve what I want, I think I would need to join item and status, sort them, and THEN split them back out. Problem is once joined, how to split them back to what they were before?
-
For you big picture you need more then .sort().
var item = @all of item; var status = @all of status; var result = []; for(var i = 0; i < item.length; i++) { result.push (status[i]+ " " + (item[i] ); };
result.sort().join(";\n")
It will sort the items alphabetically and write the status behind the item like:
yStatus Bitem;
yStatus Citem;
xStatus Aitem;"\n" is for line break; in the brackets behind .join you can use any separator you want . The output you can manipulate in the brackets behind result.push, like ("- STATUS: " + status[i] + " ... ITEM: " + item[i]) . You'll get
- STATUS: yStatus ... ITEM: Bitem;
- STATUS: yStatus ... ITEM: Citem;
- STATUS: xStatus ... ITEM: Aitem;If you want to sort them into groups by status:
var item = @all of item; var status = @all of status; var resultYstatus = []; for(var i = 0; i < item.length; i++) { if(status[i] = "yStatus"){ result.push (item[i] ); } }; var resultXstatus = []; for(var i = 0; i < item.length; i++) { if(status[i] = "xStatus"){ result.push (item[i] ); } }; "All items with yStatus: \n" + resultYstatus.sort().join(";\n") + "\n\n" + "All items with yStatus: \n" + resultYstatus.sort().join(";\n")
will show:
All items with yStatus:
Bitem;
Citem;All items with xStatus:
AitemBut when using this for-loops it's necessary that each item-field has a value and each status field has a value.
Rainer
rg@delos-consulting.com -
Wow! What a response... I truly appreciate it. Really helps me get a sense of how to think about these things and the syntax possibilities.
I tried the code below, but for some reason there are rogue commas one every row but the first row:
var Item = @All of Item;
var Status = @All of Status;
var Result = [];for(var i = 0; i < Item.length; i++)
{
Result.push (Item[i] + " | " + Status[i] + "\n")
}Result.sort()
write = Result + ""
Output is
Item | Status
,Item | Status
,Item | StatusAny idea what's going on there?
-
Follow-up question:
I have this code that works for putting the items in a table and sorting them by Step #. I have two for loops, one collects the items and sorts them for each app. The problem is that I want to combine both app item lists into one table and I can't seem to figure out how to do it without messing up the table. I've been playing with Table.push(DocList + Minutes.List) but that doesn't seem to work. Any suggestions?
//Document Rows
for (i=0; i < DocStatus.length; i++)
{
DocList.push(
DocStep[i] + " | " + Item[i] + "
}
DocList.sort()// Minutes Rows
for (i=0; i < MinutesStatus.length; i++)
{
MinutesList.push(
MinuteStep[i] + " | " + Minute[i] + "
}
MinutesList.sort() -
I want the table to look like:
Documents | Status
Minutes | StatusBut to appear as one long table with just Documents | Status as the headings and then rows of the documents and minutes with their statuses (Minutes are a type of document just tracked in a different app). Make sense?
-
The goal is:
Documents | Status
dokA | statusA
dokB | statusB
dokC | statusC
dokD | statusD
minA | statusA
minB | statusB
minC | statusC
minD | statusDThe reason I wanted to push them into a new array called Table was so that I could then sort them all with Table.sort(). So really I want to achieve:
Documents | Status
dokA | statusA
minA | statusA
dokB | statusB
minB | statusB
dokC | statusC
minC | statusC
dokD | statusD
minD | statusDAny thoughts on achieving that?
-
For the first alternative ("goal") you can use this
DocList.sort().join("\n") + "\n" + MinutesList.sort().join("\n")
for the second alternative ("achieve") you can try his
var bothLists = DocList.concat(MinutesList); bothLists.sort().join("\n")
Both arrays are joined to one array and than all elements of the new array sorted alphabetically. It depends on the names of DocStep and MinutesStep if they are sorted alternately as you like it.
Rainer
Please sign in to leave a comment.
Comments
14 comments