- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 08:26 AM - edited 05-02-2023 08:27 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 09:53 AM
Working fine amit,
just the format missed, I have corrected it and working now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 09:03 AM - edited 05-02-2023 09:05 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 06:36 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 09:16 AM
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:
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.
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 09:53 AM
Working fine amit,
just the format missed, I have corrected it and working now.