How do I create an incident or request item - based on a record being added to a table?

catho
Tera Expert

Hi,

my first question - so please excuse me if I have missed anything obvious.

I would like to create a request item - with some pre-populated fields - based on when a record is added to an unrelated table.

So far I have looked at trying to do it by either events, or business rules - but not having much luck (I'm also very green with scripting).

Does anyone have some pointers of how you would implement this?

Thanks,

Cath

1 ACCEPTED SOLUTION

Shishir Srivast
Mega Sage

Hi Cath,



You can do through Business Rule, let me explain how through scripting since you are new in scripting. This might help you.



For Example: I am here trying to create an Incident when new Record gets added in Service Request (sc_request) table, checking condition that after new record is inserted and state of the newly inserted record in Open then create incident with some populated values.



find_real_file.png


find_real_file.png



(function executeRule(current, previous /*null when async*/) {


  // Add your code here


  var gr = new GlideRecord('incident');


  gr.caller_id = gs.getUserID();


  gr.comments = 'New Incident on addition of new Record in Service Request Table';


  gr.short_description = 'New Incident on addition of new Record in Service Request Table';


  gr.category = "inquiry";


  gr.incident_state = IncidentState.NEW;


  gr.contact_type = "email";


  gr.insert();


})(current, previous);



Result:


find_real_file.png



Hope this will help you to understand how to achieve, just replace the table name on which when you insert new record incident should be created.


View solution in original post

21 REPLIES 21

DUGGI
Giga Guru

Hi Cath,



Trigger business on the unrelated table,when ever insert new record and pyou want to create Request   use cart api in script



Service Catalog Script API - ServiceNow Wiki



 var cartId = GlideGuid.generate(null); var cart = new Cart(cartId); var item = cart.addItem('e2132865c0a8016500108d9cee411699'); var rc = cart.placeOrder(); gs.addInfoMessage(rc.number); 

Ordering twelve BlackBerries:


 var cartId = GlideGuid.generate(null); var cart = new Cart(cartId); var item = cart.addItem('e2132865c0a8016500108d9cee411699', 12); var rc = cart.placeOrder(); gs.addInfoMessage(rc.number); 

Ordering an executive desktop and setting its OS:


 var cartId = GlideGuid.generate(null); var cart = new Cart(cartId); var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f'); cart.setVariable(item, 'os', 'Linux Red Hat'); var rc = cart.placeOrder(); gs.addInfoMessage(rc.number);

sachin_namjoshi
Kilo Patron
Kilo Patron

Hi Cath,



Please look into new call functionality which creates either incident, request item based on call type.



Create a new call



Regards,


Sachin


ludijormajordeb
Tera Contributor

Hi Cath,



One way to do that is to create a business rule on the incident table, that runs after a record is inserted. Then you could use the GlideRecord API to create records on the Requested Item table.



As you want some fields to be pre-populated, the requested item records could be created from a template.



If this post has helped, please choose 'Like', 'Helpful' or 'Correct'


Shishir Srivast
Mega Sage

Hi Cath,



You can do through Business Rule, let me explain how through scripting since you are new in scripting. This might help you.



For Example: I am here trying to create an Incident when new Record gets added in Service Request (sc_request) table, checking condition that after new record is inserted and state of the newly inserted record in Open then create incident with some populated values.



find_real_file.png


find_real_file.png



(function executeRule(current, previous /*null when async*/) {


  // Add your code here


  var gr = new GlideRecord('incident');


  gr.caller_id = gs.getUserID();


  gr.comments = 'New Incident on addition of new Record in Service Request Table';


  gr.short_description = 'New Incident on addition of new Record in Service Request Table';


  gr.category = "inquiry";


  gr.incident_state = IncidentState.NEW;


  gr.contact_type = "email";


  gr.insert();


})(current, previous);



Result:


find_real_file.png



Hope this will help you to understand how to achieve, just replace the table name on which when you insert new record incident should be created.