Can someone help in below script to compare date [if " last discovered " is greater than 30 days of the current date]

Sachin Gavhane
Giga Guru

I wanna check if "last discovered" date is greater than 30 days of the current date. please help me to rectify below script. will client script applied on database instance class is applicable to all its child classes? i wanna make it applicable to all its child classes. @shloke04 can you help

find_real_file.png

1 ACCEPTED SOLUTION

Well, you can use the business rule as follows;

When to run

find_real_file.png

find_real_file.png

 

Actions

find_real_file.png

 

Advanced

find_real_file.png

 

I believe that you are looking for a way to schedule a GlideRecord on this table and set the status of those records which have not been discovered for more than 30 days.

In case, if this is your requirement then you need to implement a scheduled job as follows;

find_real_file.png

Also make sure to adjust Run and Time fields as per your requirements.

 

Hopefully this will help you.

View solution in original post

9 REPLIES 9

I have written BR as per your instructions, but unable to set value of Status {install_status} for table database instance, can you please check at ur end for that field , i guess it is of type integer with choices.

find_real_file.png

@Sachin Gavhane 

That is correct. Install Status is an integer type field so you need to update your BR script as below:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var last_discovered = new GlideDateTime(current.last_discovered);
    var getCurrentDate = new GlideDateTime();

    var time_diff = gs.dateDiff(last_discovered, getCurrentDate, true);
    if (time_diff >= 2592000) {
        gs.addErrorMessage('30 days have crossed');
        current.install_status = 100; // 100 is the value for Absent
    }


})(current, previous);

This should work for you.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Guys, I tried a lot but unable to set the value of field Status on database instance table

 

 

please check line 7,8 and 9 , tried with all combinations but status is not updated.  can you please help

@Sachin Gavhane 

Just want to check if you have marked the appropriate response as correct here, as I have clearly first suggested you to use a Business Rule approach and shared the script with you which you need to use here along with proper screenshots

However I was not aware that you need to set your Install status field which was not mentioned in your question before and then have updated it correctly.

I do not have any concern for other answer to be marked as correct but just thought of checking as I first called out and routed you in the correct direction of using a Business Rule

 

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

yes it is my mistake that i didnt mention that i need to update field.

I am also concern of existing records and observed schedule job is better option.

I appreciate all your help always and yes your answer is also tending towards correct direction but i used scheduled job