How to calculate only the number of days for a particular state without using metric instance

SAS21
Tera Guru

I have a requirement for reporting purpose on a custom table.  Need to calculate  only the no of days the request is in a particular state.

 

If the request changes from state 1  to capture the no of days the request is in state 1

 If the request changes from state 2 need to capture the no of days the request is in state 2

 

if the user changes the state from state 2 to state 1 vice versa , duration days should append to the existing 

 

New to coding. Appreciate if someone helps with the code. 

 

 

 

 

1 ACCEPTED SOLUTION

AndersBGS
Tera Patron
Tera Patron

Hi @SAS21 ,

 

Why would you utilize code and not metrics which is in general the purpose of your requirement? 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

2 REPLIES 2

nageswariM
Tera Contributor

Follow this approach
Step 1: Create 2 fields >> 1 to store timestamp of Previous state change (Default value > opened date)

                                       >>2 one to capture State||Days from onChange

Step2: onChange Client script on State
           >> Calculate the days between 1st field and current date
           >>Set 1st field value current timestamp
           >> Set and append 2 field value  as current state|:days 

Iterate Step2 

However  field2 will show as State1:2days ,State2:3days

***Hit answered and helpful if this helped to solve your question

AndersBGS
Tera Patron
Tera Patron

Hi @SAS21 ,

 

Why would you utilize code and not metrics which is in general the purpose of your requirement? 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/