Post

2 followers Follow
0
Avatar

number of items present in an app

Hi,

I want to calculate the number of items present in my deals app that have deal start date from 1st  Jan to 30th November; in another app, then use this number for other calculations, how do I do this?

Thanks for your help! 

Janki Somani

Please sign in to leave a comment.

11 comments

0
Avatar

Hi Janki,

is the Deal app related to the other app (through a relationship field)?

If so you can do this in the calculation field in the other app:

var start = 101;
var end = 1130;
var date = @all of date field in deals app;
var sum = 0;
for(var i = 0, i < date.length; i++){
dateAsNumber = Number(moment(date[i]).format("MDD")) || 0,
if(dateAsNumber >= start && dateAsNumber <= end){
sum +=1;
}};
sum

Rainer

Rainer Grabowski 0 votes
Comment actions Permalink
0
Avatar

Hi Rainer,

Thanks for getting back to me.

The code is just previewing 0. Please help!

 

Janki Somani 0 votes
Comment actions Permalink
0
Avatar

Hello Janki,

can you please share some screenshots:
1 of the calculation field (is should show the preview under the field). . In an item in the other app which has related Deals-items click "Modify template" , click into the calc field, hit the space key so that the preview is shown, take the screenshot.
2. of a Deals-items where I can see the date field
3. of the item where I can see the relationship field which connects both apps.

Rainer

Rainer Grabowski 0 votes
Comment actions Permalink
0
Avatar

Looks ok.

Enter as last line (under sum)
date.length
What does the preview show? 
If the result = 0, no item is related; if the result is > 0, add another calc field (for testing only) and enter
@all of Deal Start Date.join("\n")
All Deal items which are related to xyz should be listed. Look if there is one with a date between Jan 1 and Nov 30. If there's none, the result 0 is correct. 

Rainer Grabowski 0 votes
Comment actions Permalink
0
Avatar

Total 3 deals have been entered.

The second calculation field is displaying today's date and current time.

Janki Somani 0 votes
Comment actions Permalink
0
Avatar

Hi,

the year must be the first part of the number:

var start = 20170101;
var end = 20171130;
var date = @all of date field in deals app;
var sum = 0;
for(var i = 0, i < date.length; i++){
dateAsNumber = Number(moment(date[i]).format("YYYYMMDD")) || 0,
if(dateAsNumber >= start && dateAsNumber <= end){
sum +=1;
}};
sum

Please check that in an existing item in the App Calculations (open an item and click modify template). Check if one or multiple Deal-item(s) is/are related to that Calculations-item.

Rainer

Rainer Grabowski 0 votes
Comment actions Permalink
0
Avatar

Hi,

The preview for the first calculation field is 0 and "Invalid value null" for the second one.


Janki Somani 0 votes
Comment actions Permalink
0
Avatar

Means that there's no deals-item linked (through the relationship field in Deals) to the calculations-item xyz.

No relation - result = 0. A calculation field can only filter/calculate with items which are related. 

Rainer Grabowski 0 votes
Comment actions Permalink
0
Avatar

In Deals you have a rel. field to Calculations but If date.length == 0 and @all of starte date. join() = null  then definitly no item is related to xyz. Look at the bottom of the item if you see any related item. 

Rainer Grabowski 0 votes
Comment actions Permalink