Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Disbale Implementation button till planned start date window arrives

sravya03
Tera Contributor

Logic  to Disbale Implementation button till planned start date window arrives.

I have written below on load client script but it is not working

 

function onLoad() {
  // Get the planned start date
  var plannedStartDate = g_form.getValue('planned_start_date');
  // Get the current date and time
  var now = new Date();
  // Convert planned start date to a Date object
  var plannedStart = new Date(plannedStartDate);
  // Check if the current date is before the planned start date
  if (now < plannedStart) {
    // Disable the Implement button
    g_form.setActionDisabled('implement', true);
  }
}
28 REPLIES 28

@Shivalika  @Medi C  can you both help here.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hello @sravya03 

 

What I got from your requirement is you want the UI Action to be present there but not working means disabled. ( Not clickable ? ) Am I correct ?? 

 

Cc @Dr Atul G- LNG 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Or, add a validation so that if the planned start date hasn’t been reached and the user clicks on the Implement UI action, an error appears, preventing the change from moving to the Implement state. @Shivalika 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Yes this works for me @Shivalika  @Dr Atul G- LNG 

Hello @sravya03 

 

Then I will suggest to go by validation as that is fairly simple. If you choose to disable it, you will need to run an on load client script and use DOM. 

 

On the other hand this validation only requires slight modification in your existing UI Action . 

 

In script part of UI action, please add below code - 

 

var now = new GlideDateTime();
var plannedStart = new GlideDateTime(plannedStartDate);

if (plannedStart > now) {
g_form.addErrorMessage("You cannot move to Implement state before the Planned Start Date.");
return;
}

 

You must add return so that function ends there. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY