Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Run workflow on RITM update

kenneth2k1
Kilo Expert

Hello all:

I haven't quite wrapped my head around workflows, but is it possible to run a workflow when a record is updated? Keep in mind for this, I cannot use an order guide because the REQ (sc_request) record needs to be created from an e-mail inbound action. From there I have been able to auto create a RITM that is attached to it for a manager to fill out important onboarding data. This is an on-boarding process. Ultimately what I would like to accomplish happens in these steps:


1) regular user completes some fields on the "FIT" RITM they have. Data must be entered into the "Type of PC" field in order to generate a RITM for the SN_Service Desk group, and data must be entered in the Office/Cubicle field in order to generate a RITM for the SN_Facilities group.

2) If these fields are filled out and the person clicks the "Update" button, I would like it to automatically close this RITM, and then generate the RITMs for the two assignment groups listed above

3) The two RITMs would also be attached to the original REQ record in order to track it.


I have written a workflow that is set on the sc_req_item table:

properties.jpg

The purpose of this workflow is to run when a RITM hits the "Closed Complete" stage and has the Item (cat_item) value of "FIT," I'd like two additional RITMs to be created - one for the Service Desk assignment group, and another for the Facilities group. Here is a look at the workflow:

workflow.jpg

The "Create Task" steps are set as such:

servdesk.jpg

The "Create Facilities RITM" is set similarly, but with the Fulfillment group being "SN_Facilities"

It doesn't seem to work as I want it to, since the RITMs are never created.


Is this all possible from the workflow? What should I add or where should I add this in order to accomplish this? Any help on this would be awesome! Thanks

1 ACCEPTED SOLUTION

manikorada
ServiceNow Employee
ServiceNow Employee

Ken,



Try to Do something like:


1) Have a Business rule on 'sc_req_item' which will run when any of the two fields change and have the script as:



// pass the sys_id of the record in 'wf_workflow' table, not the wf_workflow_version table.


startWorkflow('<<sys_id>> of the Workflow');



function startWorkflow(id) {


    var w = new Workflow();


    var context = w.startFlow(id, current, current.operation(), getVars());


}



function getVars() {


    var vars = {};


    for (var n in current.variables)


          vars[n] = current.variables[n];


   


    return vars;


}



2) Now in you 'Create Task' activity in the Advance Section, have something like this also:


    task.request = current.request.sys_id;


View solution in original post

11 REPLIES 11

After reviewing, that would have been a good idea, but the additional license thing unfortunately isn't going to be an option. I'm just going to have to work off the REQ/RITM tables. So I can explain as much as possible, what we are trying to accomplish is a new employee onboarding process (we call it FIT), but one where the originating parent record is already created by an inbound email action. I have that all set, and it auto creates the REQ and RITM correctly. I have set the requested_for populate properly so that the user can come in and add all the new hire setup info on the RITM.



From there, I have created a business rule that has these conditions:


busrule.jpg


Under the Advanced tab I've entered this script, which I'm hoping creates RITMs under the same REQ as my original RITM:



createRITMS();




function createRITMS() {


//var type = g_form.getValue('sys_display.original.task.number');


  var openfor = gs.getUserID();


  var requestSysId = 'REQ0076278';// current.number.getDisplayValue();


  var emp = 'Jack Jones';


  var postitle = 'IT Contractor';


  var dept = 'IT';


  var mgr = 'Test Ed';


  var bussite = 'San Diego';


  var hiredt = '01/01/2015';


  var deptcode = '3011';



    //Create Facilities RITM


    var grFac = new GlideRecord ("sc_req_item");


    grFac.initialize();


    grFac.requested_for = openfor;


    grFac.cat_item = '67d039463d8271006f3d1d29f302206a'; //Facilities


    grFac.parent = requestSysId;


    grFac.request = requestSysId;


    grFac.priority= '3 - Medium';


    var RITM1sysId = grFac.insert();




      //Create Service Desk RITM


    var grSD = new GlideRecord ("sc_req_item");


    grSD.initialize();


    grSD.requested_for = openfor;


    grSD.cat_item = '31bc246a914561006f3d5412ffb1c492';   // Computer Hardware


    grSD.parent = requestSysId;


    grSD.request = requestSysId;


    grSD.priority= '3 - Medium';


    var RITM2sysId = grSD.insert();


}



...Just realized it works! But I'm pretty dumb when it comes to javascript but I'm trying to learn. And any advice on how the syntax goes to set those variables from values on the current RITM would be awesome! I would like to set the parent and request values at least.



As always thanks for advice!


This bit is incorrect: var requestSysId = 'REQ0076278';// current.number.getDisplayValue();



You need to assign a sys_id to a reference field, but you're passing it a number. Or you can use .setDisplayValue(number) to set it using the number.



To copy the Parent Request use one of the following:



var parentID = current.parent; // or current.parent.sys_id (same result)


grFac.parent = parentID;


OR


var ParentNumber = current.parent.getDisplayValue(); // or current.parent.number (same result)


grFac.parent.setDisplayValue(ParentNumber);