Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Ryan Palamara
ServiceNow Employee

One of the powerful outcomes of using Remote Record Producers (RRP) with Service Bridge, is that once a consumer submits an RRP, you will collect structured data that can be used to automate your workflows on your Provider instance. When configuring a Remote Record Producer, a subflow is linked to drive the fulfillment. It is quick and easy to extract the variables and pass them along to other tasks and drive automation. Here is an example on this is done:

 

1. I started by making a copy of the OOTB Service Bridge subflow "Create Incident from Provider Task". 

 

RyanPalamara_0-1716476568417.png

 

2. Next we will add an action before the existing "Create Incident Record" action. We will select the "Get Catalog Variables" action that is under the ServiceNow Core spoke. 

 

RyanPalamara_1-1716476749977.png

3. In this action, we need to fill in the following fields:

  • Submitted Request - This will be the "Provider Task" record that is provided in the Subflow Inputs
  • Template Catalog Items and Variable Sets - From the picker, we will find the name of the RRP that this subflow will be used for. 
  • Catalog Variables - Once you have filled in the above field, you will now see the variables that you have defined in your RRP show in the "Available" section on the left. Select the variables that you will use later in the subflow and click the right arrow to move them into the "Selected" section. 

RyanPalamara_3-1716477115029.png

4. Now those variables will show up as pills that can be used in later steps in the Subflow. 

5. As an example, I have updated the OOTB Create Incident Record action to use variables that I have collected:

  • Short Description is populated by the "title" variable
  • Description is populated by the "summary" variable
  • Priority is populated by to the "priority" variable
  • Category is populated by the "category" variable
  • Subcategory uses a script to determine which of the variable to populate, based on the value of the "category" variable

6. Now when my incident is created, I am automatically setting the short description, description, priority, category, and sub-category. 

 

RyanPalamara_4-1716477447540.png

 

Using the Get Catalog Variables action, it is easy to use the variables from your RRP in your flow. 

 

4 Comments
Nuno Oliveira
Mega Guru

Hi there,

 

The solution seems to be useful, however it isn't completely dynamic as you need to add the specific RRP to the template field and the subflow should be reusable, which in this it won't be for different RRP. 🙂 

 

Best regards

spike
Mega Sage

I had the same thought @Nuno Oliveira. I want to create RITMs on the provider side when the RRP is submitted on the consumer side. There doesn't appear to be any way to do this OOTB. At least not without creating your own flow for each RRP and even then things don't work correctly without some tweaking.

ShaneDXC
Tera Contributor

@spike, I am looking for the same (create RITMs on the provider side when the RRP is submitted on the consumer side).  As the RRP contains the associated cat_item sys_id when the RRP is generated via the "Publish to Service Exchange" UI action, it seems a generalized subflow could be created to achieve the goal without needing a targeted flow for each RRP.
Did you come to a solution? 

spike
Mega Sage

@ShaneDXC Yes I did. I found a post where someone had done similar, although typically can't find it now.

 

What I've ended up doing is this:

1. Create a new catalog item.

2. Publish it to Service Exchange.

3. The flow that runs for the RRP calls this code in an action. This code raises the RITM created in step 1 above. All based on the naming being the same:

 

(function execute(inputs, outputs) {

    var providerTask = inputs.provider_task;
    var cat_item_id = providerTask.record_producer.cat_item.toString();
    var varArray = JSON.parse(providerTask.vars_json);

    // Start the cart
    var cart = new sn_sc.CartJS();

    // Start to build the cart map
    var item = {
            sysparm_id: cat_item_id,
            sysparm_quantity: '1', 
            sysparm_requested_for: providerTask.opened_by.toString(),
            variables: {},
    };


	// Build map of question variables
	for (var i = 0; i < varArray.length; i++) {

		var varGR = new GlideRecord('item_option_new');
		if (varGR.get(varArray[i].questionID)) {

			var varName = varGR.name;      // MUST be question "Name"
			var varValue = varArray[i].value;
            
            if (varValue === null) {
                varValue = '';
            }

            // Server-side CartJS wants an object
            item.variables[varName] = String(varValue);

		}
	}

    var requestDetails = cart.orderNow(item);

    // Now find the RITM that we can return to the Provider task
    var ritmGR = new GlideRecord('sc_req_item');
    ritmGR.addQuery('request', requestDetails.request_id);
    ritmGR.query();

    if (ritmGR.next()){
        outputs.ritm = ritmGR;
    }

})(inputs, outputs);

4. The Parent, Fulfilment table and Fulfilment task are then updated with the details of the RITM that was created.

 

I also then had to create code to replicate comments, states etc between the two. OOTB SE only does that for incidents, not for catalog tasks.

 

Hope this helps!