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.

Flow Context UI Action from custom table

Community Alums
Not applicable

I have custom tables that also have Flows that attach themselves.

I'm trying to replicate the "Flow Context" UI action on a custom table so that I can see these active flows, however the default solution thats used for RITMs obviously does not work.

How can this be modified to work correctly?

function showFlowContext () {
	var url = new GlideURL('catalog_flow_context.do');
	url.addParam('sysparm_sys_id', g_form.getUniqueValue());
	url.addParam('sysparm_ck', g_form.getValue("sysparm_ck"));
	g_navigation.open(url.getURL(), "_blank");
}

Currently it obviously does not redirect me to the correct place, the custom table does not have a sysparm_ck value.

find_real_file.png

1 ACCEPTED SOLUTION

Community Alums
Not applicable

I managed to resolve this myself with an Ajax call.

function showFlowContext() {
    var id = g_form.getUniqueValue();
    var ga = new GlideAjax('AjaxUtils');
    ga.addParam('sysparm_name', 'getFlowContext');
    ga.addParam('sysparm_id', id);
    ga.getXMLAnswer(getValue);

    function getValue(response) {
        var answer = JSON.parse(response);
        if (answer["success"] == "true") {
	    g_navigation.open('/$flow-designer.do#/operations/context/' + answer.id, "_blank");
        }
    }

}
var AjaxUtils = Class.create();
AjaxUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	getFlowContext: function(){
		var id = this.getParameter('sysparm_id');
		var ctx = new GlideRecord("sys_flow_context");
		ctx.addEncodedQuery("source_table=table_name_here^source_record="+id);
		ctx.query();
		if(ctx.next()){
			var results = {
				"success":"true",
				"id":ctx.getUniqueValue()
			};
			return JSON.stringify(results);
		}
		gs.addErrorMessage("Flow Context does not exist for this record.");
		var results = {
			"success":"false"
		};
		return JSON.stringify(results);
	},
	
    type: 'AjaxUtils'
});

View solution in original post

16 REPLIES 16

Ashish Arovind1
Giga Expert

Try something like this :

 

var gr = new GlideRecord('sys_flow_context');
gr.addQuery('source_record', current.sys_id);
gr.query();
if (gr.next()) {
var url = 'sys_flow_context.do?sys_id=' + gr.sys_id.toString();
action.setRedirectURL(url);
} else {
gs.addErrorMessage("Record not found"));
action.setRedirectURL(current);

}

 

Please mark this as correct if it solves your query to help community 

Please mark this as helpful if it helped you to help community .

Regards

Ashish Raj

Hi,

Nothing happened when I clicked it.

2023_08_23_10_48_38_Flow_Context_UI_Action_ServiceNow.png

Community Alums
Not applicable

I managed to resolve this myself with an Ajax call.

function showFlowContext() {
    var id = g_form.getUniqueValue();
    var ga = new GlideAjax('AjaxUtils');
    ga.addParam('sysparm_name', 'getFlowContext');
    ga.addParam('sysparm_id', id);
    ga.getXMLAnswer(getValue);

    function getValue(response) {
        var answer = JSON.parse(response);
        if (answer["success"] == "true") {
	    g_navigation.open('/$flow-designer.do#/operations/context/' + answer.id, "_blank");
        }
    }

}
var AjaxUtils = Class.create();
AjaxUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	getFlowContext: function(){
		var id = this.getParameter('sysparm_id');
		var ctx = new GlideRecord("sys_flow_context");
		ctx.addEncodedQuery("source_table=table_name_here^source_record="+id);
		ctx.query();
		if(ctx.next()){
			var results = {
				"success":"true",
				"id":ctx.getUniqueValue()
			};
			return JSON.stringify(results);
		}
		gs.addErrorMessage("Flow Context does not exist for this record.");
		var results = {
			"success":"false"
		};
		return JSON.stringify(results);
	},
	
    type: 'AjaxUtils'
});

Aidan, can you let me know where you're putting this second Ajax script? Is it in your UI action or did you make a script include, or client script etc.? I need to do the same thing as you and I'm stuck with the second script you included:

var AjaxUtils = Class.create();
AjaxUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	getFlowContext: function(){
		var id = this.getParameter('sysparm_id');
		var ctx = new GlideRecord("sys_flow_context");
		ctx.addEncodedQuery("source_table=table_name_here^source_record="+id);
		ctx.query();
		if(ctx.next()){
			var results = {
				"success":"true",
				"id":ctx.getUniqueValue()
			};
			return JSON.stringify(results);
		}
		gs.addErrorMessage("Flow Context does not exist for this record.");
		var results = {
			"success":"false"
		};
		return JSON.stringify(results);
	},
	
    type: 'AjaxUtils'
});