Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Evaluator: com.glide.script.RhinoEcmaError: "event" is not defined.

Dinesh
Tera Guru

for below script we are getting error like below.

Evaluator: com.glide.script.RhinoEcmaError: "event" is not defined.

 

Dinesh_0-1672217319438.png

var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", event.parm1);//this line not working
//gr.addQuery("sys_id", "3883f4c0730123002728660c4cf6a754");//working but only one record is updating..
gr.query();
if (gr.next()) {
gs.info("User is deactivated" + gr.user_name);
gr.active = false;
gr.update();
}

can any one help me for this

2 ACCEPTED SOLUTIONS

Not applicable

For Script action --Deactive User set action name=deactivate_user..

It will deactivate your user which were not logged in from 85 days.

 

once changes are done please go to Schedule Job and use UI action Execute now to check the user are getting deactivated .

 

Hope this helps.

 

 

Regards,

Hemant 

**Please mark my answer correct or helpful based on the impact**

View solution in original post

Finally working  as per below change done.

Dinesh_0-1672229447962.png

 

View solution in original post

9 REPLIES 9

Not applicable

 Hi @Dinesh ,

 

As event.parm1 is not defined in background script.

 

So your getting error.

 

Regards,

Hemant 

**Please mark my answer correct or helpful based on the impact**

Hi @Community Alums ,

 

I am using script from below link.. even it is not working when event is triggered.but notifications are triggering correctly.

https://www.servicenow.com/community/developer-forum/user-deactivate-after-90-from-user-table/m-p/14...

Not applicable

@Dinesh  Please share your use case and code? and where you are using that code.

 

Thanks,

Hemant

 

User Deactivate after 85 days and send an email to the user before deactivate:

 

 

Notify users 85 days and deactivate

Scheduled job

 

 

var gr = new GlideRecord("sys_user");
gr.addActiveQuery();
gr.addQuery("last_login",'<=',gs.daysAgo(85));

gr.query();
while(gr.next()) {
  gs.eventQueue('user_not_logged_in_85days_ago', gr, gr.getValue("email")); 
  gs.eventQueue('deactivate_user', gr, gr.getValue("sys_id")); 
  
}

 

 event registry:

Dinesh_2-1672221486189.pngDinesh_3-1672221523663.png

 

 

 

 

 script actions

Name: Deactive User

 

var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id",event.parm1);
//gr.addQuery("sys_id", "8ff5b254b33213005e3de13516a8dcf7");
gr.query();
if (gr.next()) {
  gs.print("User is deactivated"+gr.user_name);
  gr.active=false;
  gr.update();
}

 

notification:

Dinesh_0-1672220855879.pngDinesh_1-1672220881684.png