Create Request>RITM>SCTask Relationship in a workflow

chadlockwood
Kilo Sage

We are creating sctasks, in a workflow that is not driven by a Service Catalog Item, for our Support Desk. The workflow is not tied to the Tasks table. Is it possible to use a Run Script activity to dynamically create a Request and an associated RITM, then use a Catalog Task to create the sctask and associate that to the RITM? We want to create this tree so that we retain the ability to dot-walk fields.

1 ACCEPTED SOLUTION

Hi Chadlockwood,


I got the reason why it was giving you "NullPointerException". It was because of the line "task.requested_for =   "SET THE USER VALUE HERE";" and "task.request_item.requested_for = "SET THE USER VALUE HERE";" as there is no requested for field on either of task and requested item table. requested item field shown on these forms are coming from request table if you check and personalize the form layout. I hope I am making sense here.



Below is the tried and tested code which you can use.



var task = new GlideRecord('sc_task');


task.initialize();


task.short_description = "ENTER THE SHORT DESCRIPTION HERE";


task.request_item.short_description = "ENTER THE SHORT DESCRIPTION FOR REQUESTED ITEM HERE";


task.request_item.request.short_description = "ENTER THE SHORT DESCRIPTION FOR REQUEST HERE";


task.request_item.request.requested_for = gs.getUserID();



task.insertWithReferences();



Please mark answered if it really resolve your issue.


View solution in original post

6 REPLIES 6

RKumar3
Tera Guru

Yes you can use a run script to create a new Request and associated Requested Item in your workflow. You can associate your sctask as well to the Requested Item. I am afraid you will end up having a Service Request with out any workflow and it will not proceed further on activities like " sctask is marked close complete"


RKumar02,



I'm very excited to hear that this is possible. Very specifically we are trying to include Requested for on our SCTasks, but we can't dot-walk if there isn't a parent Request/RITM. Could you elaborate on how to accomplish creating a Request with an associated RITM and how to associate subsequent SCTasks all within a workflow? The two workflows where we would use this are point at a custom table and the global table.



Regards,


Chad


Chadlockwood,


You can try something like given below while creating a task record. it will also create a requested item and a request record along with the task record. Please note this is not a tested script and you may have to make some changes here. It will surely give you the idea though.



var task = new GlideRecord('sc_task');
task.initialize();
task.short_description = "ENTER THE SHORT DESCRIPTION HERE";
task.requested_for =   "SET THE USER VALUE HERE";
task.request_item.short_description = "ENTER THE SHORT DESCRIPTION FOR REQUESTED ITEM HERE";
task.request_item.requested_for = "SET THE USER VALUE HERE";
task.request.short_description = "ENTER THE SHORT DESCRIPTION FOR REQUESTED ITEM HERE";
task.request.requested_for = "SET THE USER VALUE HERE";


task.insertWithReferences();


RKumar02,


I have attempted to use your code as-is and with some edits. I set the requested_for lines to the sys_id of my test user. This works to set the requested_for on the REQ, however, I get an error on the code:


Evaluator: java.lang.NullPointerException


  Caused by error in script at line 10


==> 10: task.insertWithReferences();



I then try commenting out the request_item and request lines. This works to create the REQ with the correct requested_for and it creates the SCTask, but no RITM and obviously the SCTask is not associated with the REQ.


It seems as though creating the RITM is the unobtainable goal.