The CreatorCon Call for Content is officially open! Get started here.

Auto populate field when creating an incident from a UI Action Button

Adam Wood
Tera Contributor

Hi 

I am looking to create an automation where our User Management team can create an incident to report that a user has left the company. My thoughts were create a button on the User form which can be clicked which does the following: 

  • Creates a new incident
  • Sets the Caller to the users name 
  • Sets Category and sub category
  • Populates the Configuration item to the users assets (Each CI has the assigned to field populated with a users name)
  • Enters details into the description field 

I have already created the button on the user form but i am unsure how to complete the above actions 

Any guides or advise is welcome 

Thank you in advance 

Adam 

 

1 ACCEPTED SOLUTION

Bit modification:)

var gr = new GlideRecord('cmdb_ci');
gr.addQuery('assigned_to',current.sys_id);
gr.query();
gr.next();

var inc = new GlideRecord("incident");
inc.initialize();
inc.caller_id = current.sys_id;
inc.category = 'addyourcategory';
inc.subcategory = 'addyoursubcategory';
inc.cmdb_ci = gr.sys_id;
inc.short_description = 'addyourdescription';
inc.insert();
action.openGlideRecord(inc);

View solution in original post

7 REPLIES 7

Pushpa Yadav1
Tera Guru

UI Action Script:

 

var inc = new GlideRecord('incident');
inc.initialize();
inc.caller_id = current.sys_id;
inc.category = 'xyz'; //choice value of category
inc.subcategory = 'pqr'; //choice value of subcategory
inc.cmdb_ci = getAssignedCI(current.sys_id);
inc.insert();
action.openGlideRecord(inc);

function getAssignedCI(user) {
 var ci = new GlideRecord('cmdb_ci');
 if (ci.get('assigned_to', user)) {
  return ci.sys_id.toString();
 }
}

Ashley Snyder1
Giga Guru

Just a tip on these code examples, instead of using something like inc.caller_id = current.sys_id; use inc.setValue('caller_id', current.sys_id); to avoid pass-by-reference.

Adam Wood
Tera Contributor

Thank you all for the advise. I added the script and this now working a treat.