Create a Demand from a record producer that also creates a child Demand Task upon submission

spmceachin
Tera Expert

I have a demand record producer. The ask is that along with the demand being created, that a child demand task also gets created. I was able to do this through Incident, but not through demand. I'm using the following script:

var gr = new GlideRecord('dmn_demand_task');
gr.initialize();
gr.dmn_demand = current.sys_id;
//gr.insert();
gr.short_description = "This is just a test";
gr.assignment_group = 'aaccc971c0a8001500fe1ff4302de101';
var task2ID = gr.insert();

 

When I try it without the above script, it creates a demand as expected. If I add the above script, I get this error:

find_real_file.png

Then it DOES create a demand task, but does NOT create a demand. So the DTASK shows up with no parent. Very strange. Any thoughts? Thanks!

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, as you have only posted part of your code the forums ability to identify your issue is limited.
Perhaps you could update this thread with clear and specific details of your configuration, including all of the code for your record producer script

spmceachin
Tera Expert

Hey Tony. Thanks for the reply. That's actually the full code. I did have some fields mapped within the code but have since removed it to isolate just the part I'd like to create the Demand Task.

So if you were you paste this code into another demand record producer as is (and just change the sys_id to an assignment group in your instance), it should perform as I described above. It creates the DTask, but somehow prevents the actual demand from being created. If you remove the code, the demand creates normally, but then no dtask. Hope that helps. Thanks again!

spmceachin
Tera Expert

Update: Making progress. Using the following code:

// //Create DTASK that is a child of the Demand
var gr = new GlideRecord('dmn_demand_task');
gr.initialize();
gr.parent = current.sys_id;
gr.short_description = "This is just a test";
gr.assignment_group = 'aaccc971c0a8001500fe1ff4302de101';
gr.parent = current.sys_id;
var task2ID = gr.insert();

There is an OOB business rule called "Prevent DemandTask Hierarchy" which I had to disable. 

It now created the Demand with a DTask underneath it. However, I now get this error:

"Error Message

Error running business rule 'Rollup Demand Actual Effort' on dmn_demand_task: DMNTSK0001122, exception: org.mozilla.javascript.EvaluatorException: Cannot convert NaN to java.lang.Long (sys_script_include.865b45af77332300132628489a106114.script; line 43)"
 
So I'm doing further investigation into this....