updating sc task state when the variable date matches with current date

Rahul Raja Sami
Tera Guru

Hi 

this is my script

 

var gr = new GlideRecord('sc_task');
gr.addQuery('number', 'NUMBER');
gr.query();
if (gr.next()) {
var today = new GlideDate();
today.setDisplayValue('yyyy-MM-dd');
if (gr.variables.termination_date == today.getValue()) {
gr.setValue('state', '2');
gr.update();
}
}

 

I am not sure why this is not working?

and one more question which type of BR suits the best for my condition?

1 ACCEPTED SOLUTION

Working fine amit,

just the format missed, I have corrected it and working now.

View solution in original post

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@Rahul Raja Sami Are you passing a valid SC Task number here

 

gr.addQuery('number', 'NUMBER');

 

As on this line you are trying to  filter records with text NUMBER.

 

Also, compare the dates as follows.

 

if (gr.variables.termination_date.getDisplayValue() == today.getDisplayValue()) {

 

Also, in your use case, I would recommend to create scheduled job to check if the termination date has been reached or not instead of using a business rule. As a business rule will only run on insert/update of record which might not be relevant for checking the termination date.

 

 

 

 

When I using the schedule job with date diff calculation.

If current date is greater than current date I mean diff <0 then need to change the sctask state to in progress

 

But state is not changing 

 

 

IMG20250226080059.jpg

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Rahul Raja Sami ,
I trust you are doing fine.

Regarding your script, can you please provide more context? Specifically, what is the intended functionality of the script, and what error messages are you encountering (if any)? Without this information, it's difficult to pinpoint the exact issue.

That being said, here are a few general troubleshooting steps that you can try:

  1. Double-check that the variable name "termination_date" matches the field name on the "sc_task" table. If the name is different, the script won't be able to find the value.

  2. Check that the "NUMBER" value in your addQuery() method is replaced with an actual task number. If the number is incorrect or missing, the script won't be able to find the correct task.

  3. Verify that the script is running as expected by adding some logging statements. For example, you can add "gs.info('Script ran successfully');" after the gr.update() line. This will allow you to see if the script is reaching that point in the code.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Working fine amit,

just the format missed, I have corrected it and working now.