use array to get related fields.
Hi there,
Im looking for an simple solution for geting field datas in a related items.
Let me explain: a Task App has 20+ fields. Project App (that related with task app) using this fields different ways. In project app, at all single field i have to predefine all Task App fields, again and again.
is there any solution for this problem?
I figured that a solution but couldnt write it correctly.
i create a calculation field in Task Item and define an array which contains all datas in same item.
RESULT:
By this way, i suppose, when i need to use a field in an another app, i will just call @GörevArray.
Probably the ' seperators comes as text to Project app. So i couldnt make them an array. how can i realise this code?
thanks for your help.
-
I think, you've 2 options:
First:
In the field GörevArray create a simple string like:@Date + "|x|"+ @Text + "|x|" + @Category
As separators between the fields take a string which is unique (e.g which would never appear in a text).
Then in the other app:
var a = @All of GörevArray;
var r = []
for(var i = 0; i < a.length; i++){
elemSplit = a[i].split("|x|");
date = elemSplit[0];
text= elemSplit[1];
category = elemSplit[2];
r.push(category);
};
r.join()or shorter
var a = @All of GörevArray;
var r = []
for(var i = 0; i < a.length; i++){
elemSplit = a[i].split("|x|");
r.push(elemSplit[2]);
};
r.join()or
var a = @All of GörevArray;
var text = 0;
var date = 1;
var category = 2;
var r = []
for(var i = 0; i < a.length; i++){
elemSplit = a[i].split("|x|");
r.push(elemSplit[category]);
};
r.join()The second option is using JSON:
In the field GörevArray create a JSON-string like:
JSON.stringify({"text": @Text, "date": @Date, "category": @Category})
Then in the other app:
var a = @All of GörevArray;
var output = ""
var r = [];
try {
for(var i=0; i < a.length; i++) {
aElem = JSON.parse(a[i]);
output = aElem.text;
if(output != null){
r.push(output);
}
}
} catch (e) {
output += e;
output = 'Could not parse JSON';
};
r.join()Try and Catch are necessary cause a Podio calculation fields needs that (s. here https://help.podio.com/hc/en-us/community/posts/202620823/comments/207048117 )
Rainer
rg@delos-consulting.com -
Rainer Hi, thanks for your help, we are in same way. i also tried solutions in link that u gave.
But i ve got some issues.First of all, i use JSON solution, its more simple to do. Because there is many string to collect.
Result is expected. There isnt any problem.
But icouldnt find the problem in second part.
in another way, i try the other code. it works clearly.
But let me know, how can i define the result a string.
thanks for your help.
this code will make my work easier and will save my time.
-
Hi,
in deneme2 it must be r.push(), not b.push().
Pro-tip: Don't just copy and paste - but check what you copy :)
The error in the last image says what's wrong: You can't use var b = try ..
Just think :) - cause you have the solution: You don't need the var b.
Take the code from the last but one image, add var c = 10; a+c.That's all.Rainer
-
Rainer, hi again.
I m not a coder, and im trying to learn JS from beginning to use Podio more effective.
I think im good at it :) But these JSON lesson is more complex for just now. I really dont understand its logic.Here is the results after your guidance.
I couldnt figure out first code. It gives only one result from array.
But i solve it the second one and i made an improvement for it. maybe it will be helpful for more Podio Users, so im sharing it.
First field, for collecting strings for array:
i changed the |x| indicator.to ß Because its a markdown and get blot the view.
Second field for split. Main change is here. Not for a one result, for calling all result easily, code take all splited parts in an array. So, i can call them like r[1] , r[2] , r[..n].
Thanks for your help.
-
Hi,
great that it works for you. But I'm curious how it can work. One thing I don't understand: Cause .length always returns a number, the result of the calculation in your first image must be in my opition something like:
Also the second calculation I don't understand, but that's maybe I don't know what's in var a (how a string a.join() would look like). Btw: r.join() is superflous in your code, it does nothing, cause r[4] follows.Rainer
-
Yes, A1[i] is my bad, sorry. I didn't use [r4], I only quoted your code, where r .join() is superflous.
You whole code can be shortened to 2 lines:
In Calculation field "Array":@field1 + "ß" + @field2 + "ß" + @field3
In Calculation field 2:
@all of Array[0].split("ß")[3]
In field Array you can also use:
A1 = [@field1,@field2,@field3]
AR1 = ""
for(var i = 0; i < A1.length; i++){
AR1+=A1[i]+"ß";
};If you get an error notification in field 2:
String(@all of Array[0].split("ß")[3])
The codes I've provided some days ago have been for multiple related items. But it seems, you only need it for one related item. and that can be done by 2 lines of code.
Rainer
-
Ok, your opinion is important for me. so, im go back to your JSON code.
i really couldnt figure out the problem with it.
first field:
its ok. nothing different with yours.
and, inotherapp, the second field:
result is 0 ?
i tried smtgh for solution. disable aElem.text;
result is:
i removed ".text" afet aElem;
result is:
how can i solve the problem? :/
thanks for your help.
-
Hi,
as I've said: Don't simply copy :)
I've used this example JSON.JSON.stringify({"text": @Text, "date": @Date, "category": @Category})
The pair
"text": @text
is called a Property, "text" is the (property) name,@text the (property) value.
To get the value you have to call the name - that you do in the lineoutput = aElem.text;
(where aElem is the object name; the object stores the properties):
Your mistake: You have copied the property name "text" from my example, but you don't have a property name "text" in your JSON. Change "text" to one of your property names and you'll get the value.But if you have only one related item, you can also use the more simple @all of array.split() method which I've explained in my last posting.
Rainer
Please sign in to leave a comment.
Comments
10 comments