UI Action Visibility

Ram khile123
Tera Contributor

Hello Folks,

I have a requirement I want to hide button from incident form for next 24 hours once clicked it and after 24 hours again its visible or abort action if user click it within 24 hours once he click first time. I tried to use below code in ui action script but its not working.

 var diffInHours = gs.dateDiff(lastClicked, gs.now(), 'hours');
            if (diffInHours < 24) {
                return false;
}

 

Much Appreciated!!

Thanks

 

5 REPLIES 5

Sanjay191
Tera Sage

Hello @Ram khile123 

Please apply below logic 

var datalastClicked = "2025-01-03 16:57:45";// just example date
var nowDate = gs.nowDateTime();

var timeDifference = gs.dateDiff(nowDate,datalastClicked,true);
gs.print("Difference::" + timeDifference);
var res =   Math.floor(timeDifference/(24 * 60 * 60 * 1000)*1000);
gs.print("Difference::" + res);
if (timeDifference < 24) {
  return false;
}
else{
return true}

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

   

Thanks for reply,

This solution will work if we have value in 'datalastClicked' field. but its not working if datalastClicked field is empty. Can you suggest me how to compare if date field is empty?

Thanks

 

Hello @Ram khile123 

Did you try to put null check condition before datediff method so that It will check if datalastClicked has some value  then it will executes otherwise not and makesure  datalastclicked has some values and also you can use the flag variable to handle this.

Thank You 

If this helps you please mark my answer as helpful or accepted solution.

Viraj Hudlikar
Giga Sage

Hello @Ram khile123 

 

You can try with something as below 

Create a field last_clicked_time (Date/Time) in the incident table

1. Retrieve the `last_clicked_time` field value from the current `incident` record.

2. IF `last_clicked_time` exists:
   a. Calculate the time difference between `last_clicked_time` and the current time.
   b. IF the difference is less than 24 hours:
      i. Display an info message: "You cannot perform this action again within 24 hours."
      ii. Abort the action.
      iii. EXIT.
   c. ELSE:
      i. Update the `last_clicked_time` field with the current timestamp.
      ii. Save the `incident` record.
      iii. Proceed with the action.

3. IF `last_clicked_time` does not exist:
   a. Set the current timestamp as the `last_clicked_time`.
   b. Save the `incident` record.

4. Proceed with the button action logic.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.