Select to view content in your preferred language

Display date fields in labels without timestamps using Arcade

788
4
Jump to solution
11-30-2023 04:50 AM
Cyril
by
Emerging Contributor

Hello,

I have a little problem with date format in the arcade expression for popup windows

Here the code :

//Connexion au Portal
var portal = Portal("portal_url")
//Récupération de la table
var table = FeatureSetByPortalItem(portal,"portal_id",1,['ID_ASFAM','LB_COD_CAGR','DT_DEB_AGR','NB_ENFANTS','TYPE_ACCUEIL','DT_FIN_AGR'])

//Filtre sur l'identifiant
var id = $feature["id_egst"]
var filtre = 'id_asfam = @ID'
var relation = Filter(table,filtre)


//Construction du texte de la fenêtre contextuelle
var popupString = ''
for (var f in relation){
    popupString +='Catégorie d\'âge : ' + f.LB_COD_CAGR + TextFormatting.NewLine +
    'Type d\'accueil : ' + f.TYPE_ACCUEIL + TextFormatting.NewLine +
    'Nombre d\'enfant(s) autorisé(s) : '  + f.NB_ENFANTS + TextFormatting.NewLine +
    'Date début : '  + f.DT_DEB_AGR + TextFormatting.NewLine +
    'Date fin : '  + f.DT_FIN_AGR + TextFormatting.NewLine + TextFormatting.NewLine    
}
return popupString

 

Here the result :

Sans-titre-2

I would like as a resut : Date début : 18/03/2024 ==> i.e 'D/M/Y'

I tried to add this code in the arcade expression but it dont work at all :

var date = $feature["DT_DEB_AGR"] + " " +
Text($feature["DT_DEB_AGR"], 'D/M/Y')

 So, is it possible to format the date as i want to (D/M/Y) in my Arcade expression and if yes how may i proceed please ?

* bonus question if you don't mind : how may i put my text in bold in my expression..; I mean this text : "Type d'accueil :" from the expression

'Type d\'accueil : ' + f.TYPE_ACCUEIL + TextFormatting.NewLine +

Many thanks.

Cyril

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Using Text is definitely the way to do it. When you say it doesn't work at all, what does it do? Does it return something other than the timestamp?

jcarlson_0-1701350453187.png

For your bonus question: you need to use an Arcade popup element rather than just a standalone expression. That would give you the ability to use HTML tags like <b> or <strong>.

Also, consider using template literals for long strings. Inside of a backtick string, you can just use a regular newline, and the expression will be a lot simpler and cleaner to look at:

var popupString = ''

var addtext = `Catégorie d\'âge : ${f.LB_COD_CAGR}
Type d\'accueil : ${f.TYPE_ACCUEIL}
Nombre d\'enfant(s) autorisé(s) : ${f.NB_ENFANTS}
Date début : ${f.DT_DEB_AGR}
Date fin : ${f.DT_FIN_AGR}
`

popupString += addtext

 I don't have your attributes to test it, but without them, you can still see the newlines coming through.

jcarlson_1-1701351036474.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

Using Text is definitely the way to do it. When you say it doesn't work at all, what does it do? Does it return something other than the timestamp?

jcarlson_0-1701350453187.png

For your bonus question: you need to use an Arcade popup element rather than just a standalone expression. That would give you the ability to use HTML tags like <b> or <strong>.

Also, consider using template literals for long strings. Inside of a backtick string, you can just use a regular newline, and the expression will be a lot simpler and cleaner to look at:

var popupString = ''

var addtext = `Catégorie d\'âge : ${f.LB_COD_CAGR}
Type d\'accueil : ${f.TYPE_ACCUEIL}
Nombre d\'enfant(s) autorisé(s) : ${f.NB_ENFANTS}
Date début : ${f.DT_DEB_AGR}
Date fin : ${f.DT_FIN_AGR}
`

popupString += addtext

 I don't have your attributes to test it, but without them, you can still see the newlines coming through.

jcarlson_1-1701351036474.png

 

- Josh Carlson
Kendall County GIS
Cyril
by
Emerging Contributor

Hi Josh,

thanks for your answear i gonna try this.

About your question if i add this following code in my expression

 

 

var date = $feature["DT_DEB_AGR"] + " " +
Text($feature["DT_DEB_AGR"], 'D/M/Y')

 

the result is : Execution Error:Field not Found : DT_DEB_AG

0 Kudos
Cyril
by
Emerging Contributor

Thanks Josh, i made it this way and it works well :

//Connexion au Portal
var portal = Portal("portal_url")
//Récupération de la table
var table = FeatureSetByPortalItem(portal,"portal_id",1,['ID_ASFAM','LB_COD_CAGR','DT_DEB_AGR','NB_ENFANTS','TYPE_ACCUEIL','DT_FIN_AGR'])

//Filtre sur l'identifiant
var id = $feature["id_egst"]
var filtre = 'id_asfam = @ID'
var relation = Filter(table,filtre)


//Construction du texte de la fenêtre contextuelle
var popupString = ''
for (var f in relation){
    popupString +='Catégorie d\'âge : ' + f.LB_COD_CAGR + TextFormatting.NewLine +
    'Type d\'accueil : ' + f.TYPE_ACCUEIL + TextFormatting.NewLine +
    'Nombre d\'enfant(s) autorisé(s) : '  + f.NB_ENFANTS + TextFormatting.NewLine +
    'Date début : '  + Text (f.DT_DEB_AGR, 'D/M/Y') + TextFormatting.NewLine +
    'Date fin : '  + Text (f.DT_FIN_AGR, 'D/M/Y') + TextFormatting.NewLine + TextFormatting.NewLine    
}
return popupString

 So many thanks a lot with your help !!

About the bonus question, i m not sure to understand but i gonna try harder !

0 Kudos
jcarlson
MVP Esteemed Contributor

You're welcome!

For the other question, check this out:

https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/part-1-introducing-arcade-pop-up-con...

- Josh Carlson
Kendall County GIS
0 Kudos