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  receiving below error because of return

 

sravya03_0-1742894610549.png

 

Hello @sravya03 

 

That's not where you need to add this code. There is no function so where to return, that's why this error code. 

 

Share me whole script screenshot I will tell the exact line to where you need to insert this code. 

 

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

Yes , I tried to fit in function but did not work..
below is the code in UI action
 
function moveToImplement() {
    g_form.setValue("state", "-1");
    gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_implement");
}

if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}

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;
}


Hello @sravya03 

 

Add it inside function set redirect() 

You have also not fetched rhe exact planned start date, I have that variable as a Demo variable, you need to replace it with exact variable in your instance. Replace plannedStartDate with current.STARTDATE (on your end variable) 

 

Then inside function redirect and then current.update() 

 

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