JavaScript for list update | Community
Skip to main content
Rch_
Level 3
July 23, 2024
Solved

JavaScript for list update

  • July 23, 2024
  • 1 reply
  • 1037 views

Hi team,

 

I have a ask where i need a javaScript which can check if a list is updated today (modified today) or not, let me know if anyone have any lead on this?

Thanks in advance.

 

Regards,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Amine_Abedour

Hello @rch_,

 

No the list id montioned in script above is really the list identifier (@id attribut of nms:group schema).

Please find bellow an adaptation of the script if you want to use it with internal name of the list:

 

var nameList = 'changeThisToInternalNameOfYourList'; var list = xtk.queryDef.create(<queryDef schema="nms:group" operation="get"> <select> <node expr="@id" /> <node expr="@lastModified" /> <node expr="@name" /> <node expr="@label" /> </select> <where> <condition expr={"@name = '"+nameList+"'"}/> </where> </queryDef>).ExecuteQuery(); var countList = xtk.queryDef.create(<queryDef operation="count" schema={"temp:group:"+list.@id}/>).ExecuteQuery().@count; var lastModified = parseTimeStamp(list.@lastModified); var todayMidnight = new Date(getCurrentDate().setHours(00,00,00)); if (lastModified > todayMidnight ){ logInfo('The group '+list.@label+' has been updated today. The count is : '+countList) }else { logInfo('The group '+list.@label+' has not been updated today. Last time it has been updated is '+formatDate(lastModified, '%4Y/%2M/%2D') +'. The count is : '+countList) }

there no scpecific folder where your list should be to use the script. The important thing is that the user who start the script (or the workflow using the script) should have acces to the list.

 

Br, 

1 reply

Amine_Abedour
Community Advisor
Community Advisor
July 24, 2024

Hello @rch_,

 

Please find bellow an example on how to do it (i've also added how to have the count of the list content).

Let's say the id of your list is 123456 :

 

 

var idList = 123456; var list = xtk.queryDef.create(<queryDef schema="nms:group" operation="get"> <select> <node expr="@id" /> <node expr="@lastModified" /> <node expr="@name" /> <node expr="@label" /> </select> <where> <condition expr={"@id ="+idList}/> </where> </queryDef>).ExecuteQuery(); var countList = xtk.queryDef.create(<queryDef operation="count" schema={"temp:group:"+list.@id}/>).ExecuteQuery().@count; var lastModified = parseTimeStamp(list.@lastModified); var todayMidnight = new Date(getCurrentDate().setHours(00,00,00)); if (lastModified > todayMidnight ){ logInfo('The group '+list.@label+' has been updated today. The count is : '+countList) }else { logInfo('The group '+list.@label+' has not been updated today. Last time it has been updated is '+formatDate(lastModified, '%4Y/%2M/%2D') +'. The count is : '+countList) }

 

 result when the list has been refreshed today : 

 

result when the list has not been updated today :

 

Br,

Amine ABEDOUR
Rch_
Rch_Author
Level 3
July 29, 2024

Hi @amine_abedour ,

 

Can you confirm if the list id mentioned in script is internal name and is there any specific folder where my list should be while using the mentioned script?

 

Thanks in advance

 

Regards,

Sukrity_Wadhwa
Community Manager
Community Manager
August 12, 2024

Hi @amine_abedour,

Can you please help @rch_ further with their query?

Thanks!

Sukrity Wadhwa