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

AshishKM
Kilo Patron
Kilo Patron

Hi @jugantanayak , 

Can you share the table name for this application record, you can apply the condition in the list view and add the same query in scheduled job and get those record.

 

-Thanks,

AshishKMishra

 


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

Hi Ashish,

Thanks for your reply.

Table name is: sn_vul_vulnerable_item

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

Hi Ashish,

Thanks for your reply.

I have written below code but when i have applied Execute button, nothing is happening.
Or am i doiing anything wrong?

Code: 

var grVI = new GlideRecord("sn_vul_app_vulnerable_item");
    grVI.addQuery("last_foundRELATIVELT@dayofweek@ago@30");
    grVI.query();
    while(grVI.next()){
        grVI.state = 3;
        grVI.update();
    }
Regards,
Juganta