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

Thank you!



I tried adding that in — and the RITM gets created — but those 2x fields populate with default info -   not what I specified.



Looking in error logs — I can see a java error — "java.lang.IllegalArgumentException: Group undefined does not exist.: java.lang.RuntimeException: java.lang.IllegalArgumentException: Group undefined does not exist.:"



Strange since everything else worked, I copied and pasted your code- and also copied and pasted team name / requestor (rather than typing it in).



I wonder if it could be something specific to our environment?


Actually I commented that segment of code out (requestor and group) and created some more RITMs and still get error - so I think the error is unrelated to that code chunk.



Frustrating!


Hi Cath,



This is a bug that was fixed - as far as I remember - in Istanbul patch 6. I had HI ticket opened about this error and that's what I was told. Didn't have a chance to test it yet though.




Regards



Greg


Thank you!



Filtering out irrelevant errors helps (especially when Im so new to scripting / reading error logs like this)


Hi Cath,



I see your code has something wrong there var gr = new GlideRecord('sc_req)item'); table name should be sc_req_item



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


  // Add your code here


  var gr = new GlideRecord('sc_req_item');



  gr.comments = 'Test new RITM';


  gr.short_description = 'Test RITM based on criteria 123';


  gr.u_requestor.setDisplayValue('Fred Smith'); //hoping field is referenced to sys_user


  gr.assignment_group.setDisplayValue('Network');


  //gr.u_requestor = 'Fred Smith'


  //gr.assignment_group = 'Test Group'


  gr.insert();


})(current, previous);



if you go below in system logs arrow will point be pointed (like ==>) where it's wrong in code,


find_real_file.png