Schedule Job script

jugantanayak
Tera Guru

Hi,

 

I need to write a schedule job script.

 

Condition: If the application vulnerable item 'last found' date is greater than 30 days in the past, set the state of the application vulnerable item to closed.

Can any one help?

Thanks in advance.

Regards,

Juganta

 

1 ACCEPTED SOLUTION

Write a new scheduled job with following script code. 

You have to care about 2 things here, 1) field name of last found and 2) state close value 

 

AshishKMishra_0-1704378699352.png

 

var grVI = new GlideRecord("sn_vul_vulnerable_item");
	grVI.addQuery("last_foundRELATIVELT@dayofweek@ago@30");
	grVI.query();
	while(grVI.next()){
		grVI.state = 7; // check the close state choice value for close
		grVI.update();

	}

 

Note: you can test this code with single record update only, just replace the while with If, If condition will execute once only ( no loop ) and check any record updated or not. After testing complete, then revert the If with while.

 

In case you have any doubt about the grVI.addQuery() then you can open the same table in list view and apply the 30 day condition on last found column and click on Run for result then copy that query using copy query action and past it in scheduled job.

 

Example of condition ( you have apply the similar on last found column in table ( sn_vul_vulnerable_item )

AshishKMishra_1-1704379153892.png

 

Let me know if it works for you or stuck some where.

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

7 REPLIES 7

add the gs.info() inside the while loop and check if flow going inside.

and add the getRowCount() before the while();

and what's state value for close state. its 3 or 7 

var grVI = new GlideRecord("sn_vul_app_vulnerable_item");
    grVI.addQuery("last_foundRELATIVELT@dayofweek@ago@30");
    grVI.query();
   gs.info("Count->"+grVI.getRowCount());
    while(grVI.next()){
        grVI.state = 3;
        grVI.update();
    }

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Thanks Ashish.

It's working.

good to know, please mark helpful also. 

TIA


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution