Select to view content in your preferred language

Issue with creating featureset using the arcade script below?

62
0
Thursday
RPGIS
by
Regular Contributor

Hi,

I have tried to fix the error that keeps occurring with the code that I am using below. I have tried researching and trying to find a solution but all of my attempts have yielded the same result. I would greatly appreciate any help with this arcade expression.

function CalendarSE(){
    var StartMDay = Date(Year(Today()),Month(Today()),1)
    var LastMDay = DateAdd(StartMDay,1,'Month')
    LastMDay = DateAdd(LastMDay,-1,'day')

    var CS = Date(DateAdd(StartMDay,-WeekDay(StartMDay),'day'))
    var CE = Date(DateAdd(LastMDay,6-WeekDay(LastMDay),'day'))
    return {'Start' : CS , 'End':CE }
}

var CS = CalendarSE()['Start']
var CE = CalendarSE()['End']

var DateField = '<dateField>'
var P = Portal('<portal>')
var Item = Filter(FeatureSetByPortalItem(P,'<itemID>',0,[DateField],False),DateField + ' Between @cs AND @CE')

var DF = 'Y-MM-DD'
var Weekdays = {
    '0':'Sunday',
    '1':'Monday',
    '2':'Tuesday',
    '3':'Wednesday',
    '4':'Thursday',
    '5':'Friday',
    '6':'Saturday'
}

var CalendarFields = []
for( var i = 0 ; i < 7 ; i++ ){
    Push(CalendarFields,{'name': Weekdays[Text(i)] , 'type':'esriFieldTypeDate'})
	Push(CalendarFields,{'name': Weekdays[Text(i)]+'Count' , 'type':'esriFieldTypeInteger'})
}
Console(CalendarFields)
var CalendarTable = {
  'fields': CalendarFields,
  'geometry' : Null,
  'features' : []
}

var DCLimit = {}
for(var i = 0; i < 43; i++){
    var T = DateAdd(CS,i,'days')
    var CD = DateAdd(T,i+1,'days')
    var Cnt = Count(Filter(Item, DateField + ' Between @T AND @CD'))
    var W = Weekdays[Text(i%7)]
    DCLimit[W] = Date(T)
    DCLimit[W+'Count']=Cnt
    if( i % 7 == 6 ){
        Push( CalendarTable.features , {'attributes': DCLimit } )
        DCLimit = {}
    }
}

CalendarTable = Featureset( Text(CalendarTable) )
return CalendarTable

Any help on this would be greatly appreciated. I would also like to know if there is a simpler way for write this than what I have now. 

0 Kudos
0 Replies