Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to set the ticket status as closed complete

Ramya SL
Tera Contributor

Hi all,

 

I created a catalog item to add new user.

var rec = new GlideRecord('sys_user');

rec.initialize();

rec.first_name=current.variables.first_name;
rec.last_name=current.variables.last_name;
rec.user_name=current.variables.user_id;
rec.department=current.variables.department;
rec.opened_at=current.variables.start_date;
rec.state=current.variables.ticket_status;

rec.insert();

 

 

Now I need to extend my above code where I have to set the ticket status as closed complete automatically for both REQ and RITM  whenever a new user is created. 

 

And I need to set a description field as "New User Onboarding"

 

short description as "New user account created" and also it should contain userid and start date details in this itself.

 

 

 

6 REPLIES 6

Hi,

I am able to set the state of RITM as closed complete.

But I am unable to set values for REQ state,description and short description through "Set value" activity.

Aniket Chavan
Tera Sage
Tera Sage

Hello @Ramya SL  ,

Please give a try to the code below and see how it works for you.

// Create new user record
var newUser = new GlideRecord('sys_user');
newUser.initialize();
newUser.first_name = current.variables.first_name;
newUser.last_name = current.variables.last_name;
newUser.user_name = current.variables.user_id;
newUser.department = current.variables.department;
newUser.opened_at = current.variables.start_date;
newUser.state = current.variables.ticket_status;
newUser.insert();

// Update RITM and REQ records status
var ritmQuery = new GlideRecord('sc_req_item');
ritmQuery.addQuery('request', current.sys_id);
ritmQuery.query();
while (ritmQuery.next()) {
    ritmQuery.state = 3; // Closed Complete
    ritmQuery.update();
}

// Close Request record
var requestQuery = new GlideRecord('sc_request');
requestQuery.addQuery('sys_id', current.sys_id);
requestQuery.query();
if (requestQuery.next()) {
    requestQuery.state = 3; // Closed Complete
    requestQuery.update();
}

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket