List context menu - g_list.action doesn't work within a callback function - UI Action

B3N_AU
Tera Guru

Hi,

I have it working when the code looks like this

function confirmApproval() {
	var apprSysId = g_sysId;
	g_list.action('52796e01974031105ca138200153af19', 'appr_list_context', apprSysId);
}

if (typeof window == 'undefined')
    updateAndRedirect();

function updateAndRedirect() {
    gs.addInfoMessage('made it!!');
}

 

But when I add a callback function. It doesn't work. The alert the line before works

function confirmApproval() {
    var apprSysId = g_sysId;
    var ga = new GlideAjax('Utils');
    ga.addParam('sysparm_name', 'goAndDoSomthing');
    ga.addParam('sysparm_apprSysId', apprSysId);
    ga.getXML(callback);

    function callback(response) {
		alert('This popup works');
		g_list.action('0feb2f0d8748b110245dbae8dabb358b', 'list_context_action', apprSysId);
    //the action sys_id and action name above are correct and if I alert apprSysId I get the right sys_id
    }
}
if (typeof window == 'undefined')
    updateAndRedirect();

function updateAndRedirect() {
   gs.addInfoMessage(this doesn't run');
}

 

Does anyone know why?

 

Don't thing it's a caching issue as I've created it from scratch.

 

Thanks Ben

1 ACCEPTED SOLUTION

Ohh Yes, g_list will not execute server side scripts (during list context)

 

More info: https://www.servicenow.com/community/developer-forum/ui-action-wont-work-as-list-context-menu/m-p/16... 

 

what's the use case here, if you still wanna show message or do some server side logic do it in script include.

something like this:

HemanthM1_0-1689569326894.png

Same output:

HemanthM1_1-1689569381807.png

 

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

6 REPLIES 6

Hemanth M1
Giga Sage
Giga Sage

Hi @B3N_AU ,

 

If you would like to use call back function and don't want to retrieve whole XML .

 

replace : ga.getXML(callback); to ga.getXMLAnswer(callback);

 

working fine:

HemanthM1_0-1689323171894.png

 

 

 

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Thanks Hemanth

It still isn't working for me. I must have something set wrong but I can't seem to find it.

Are you able to send through the xml of your working UI Action?

That way I will be able to see where I've gone wrong.

Hi @B3N_AU ,

 

i think issue with this line: 

var apprSysId = g_sysId;

if you want to fetch the sys_id the selected record here you go

 

UI action: Make sure you update the action sys_id

function confirmApproval() {
    var apprSysId =g_list.getChecked(); //get the sys_id of the clicked record
    var ga = new GlideAjax('Utils');
    ga.addParam('sysparm_name', 'goAndDoSomthing');
    ga.addParam('sysparm_apprSysId', apprSysId);
    ga.getXMLAnswer(callback);

    function callback(response) {
		alert(response);
		g_list.action('47e168d1974435101eafb0efe153af25', 'list_context_action',apprSysId);
    //the action sys_id and action name above are correct and if I alert apprSysId I get the right sys_id
    }
}
if (typeof window == 'undefined')
    updateAndRedirect();

function updateAndRedirect() {
   gs.addInfoMessage("this doesn't run");
}

screenshot :

HemanthM1_0-1689513139405.png

script include:

Utils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	goAndDoSomthing: function(){
var clicked = this.getParameter('sysparm_apprSysId');
return clicked;

	},

    type: 'Utils'
});

screenshot:

HemanthM1_1-1689513210201.png

 

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

I recreated what you gave me and I can confirm that it works as expected.

You created the UI Action as a List banner button, not as List context menu (mentioned in the question subject)

When I change the type to List context menu, the server side code stops working again.

 

Would you be able to try it out and see if you get the same?