Expand my Community achievements bar.

SOLVED

JavaScript for list update

Avatar

Level 2

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,

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @fgtrrt,

 

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, 

View solution in original post

4 Replies

Avatar

Community Advisor

Hello @fgtrrt,

 

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 : 

Amine_Abedour_0-1721811666466.png

 

result when the list has not been updated today :

Amine_Abedour_1-1721811723391.png

 

Br,

Avatar

Level 2

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,

Avatar

Administrator

Hi @Amine_Abedour,

Can you please help @fgtrrt further with their query?

Thanks!



Sukrity Wadhwa

Avatar

Correct answer by
Community Advisor

Hello @fgtrrt,

 

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,