Create HR case from UI Action

palmen
Tera Guru

I'm trying to create a HR case from a UI Action on the Call module.

I'm using the OOTB UI Action and modify it to create a HR Case instead of an Incident, the HR Case isn't created though for some reason.

I've tried doing it with a background script and get the same result

Trying to create a HR Case doesn't work, nothing is created but a number is consumed in the number serie.

var gr = new GlideRecord('hr_case');

gr.newRecord();

gr.short_description = 'TEST';

gr.insert();

If I try doing the same for Incident or Finance Request it works fine and record is created.

var gr = new GlideRecord('incident');

gr.newRecord();

gr.short_description = 'TEST';

gr.insert();

Any idea why a HR Case isn't created?

1 ACCEPTED SOLUTION

I just tried from Call module and it did create a HR case, but only if I wrap it in a function:



(function(current, previous, gs, action) {


     


      var gr = new GlideRecord('hr_case');


      gr.newRecord();


      gr.short_description = 'TEST';


      //gr.opened_for = gs.getUserID();


      gr.opened_for = current.caller;


     


      gr.insert();


})(current, previous, gs, action);


View solution in original post

8 REPLIES 8

I just tried from Call module and it did create a HR case, but only if I wrap it in a function:



(function(current, previous, gs, action) {


     


      var gr = new GlideRecord('hr_case');


      gr.newRecord();


      gr.short_description = 'TEST';


      //gr.opened_for = gs.getUserID();


      gr.opened_for = current.caller;


     


      gr.insert();


})(current, previous, gs, action);


I can verify what Michael.Fry say - also when executed from a Background Script.


If I wrap the code in a function, then the HR Case is created - but without the function the record seems to be created (a sys_id is returned from the gr.insert() function) but it's not to be found anywhere (not even in the task table). I don't understand this behaviour rigth now (Helsinki Patch 3 Hotfix 7).



In the Background Script my wrapper function is simply:


(function() {


        // My code


})();


It works when I wrap it into a function, no idea why it doesn't work without it when you can create Finance, Incidents, Changes and other type of records without wrapping it into a function.


I had tried changing the order to a higher number, thinking something was causing conflict preventing hr case from being created, but that didn't work either. Not sure why must be in function at this point.