Comments on: Attach an event listener to a related list button https://servicenowguru.com/client-scripts-scripting/attach-event-listener-related-list-button/ ServiceNow Consulting Scripting Administration Development Tue, 28 May 2024 20:10:46 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Charles https://servicenowguru.com/client-scripts-scripting/attach-event-listener-related-list-button/#comment-8950 Tue, 15 Apr 2014 14:47:59 +0000 https://servicenowguru.wpengine.com/?p=4065#comment-8950 Thanks for this. I was finally able to get it to work. The stumbling block I ran into is my listID didn’t look anything like the format above. I’m using two custom tables with a custom relationship. Via a DOM inspector I was able to find the name. It looks like this:

list_nav_tablename.REL:sysidForRelationship

Hopefully this helps someone else.

Charles

]]>
By: Ashwin https://servicenowguru.com/client-scripts-scripting/attach-event-listener-related-list-button/#comment-8949 Thu, 25 Jul 2013 16:06:06 +0000 https://servicenowguru.wpengine.com/?p=4065#comment-8949 Hi Mark,

I tried the above code to enable this functionality. However, it did pop up the alert message and once I confirmed it by clicking OK, but the slush bucket with affected ci’c did not show up.

Below is my code

function onLoad() {
//Attach an event listener to the ‘Edit’ button on the ‘Affected CIs’ related list
var buttonText = ‘Edit…’;
var listID = ‘change_request.task_ci.task_list’;
//Find all buttons for the ‘Affected CIs list’
var buttons = $(listID).select(‘button’);
buttons.each(function(elmt) {
if(elmt.innerHTML.indexOf(buttonText) > -1){
//If the button text matches attach an event listener
Event.observe(elmt, ‘click’, customOnClick);
}
});

}
function customOnClick(){
alert(‘You clicked me!’);

var uri = action.getGlideURI();
var path = uri.getFileFromPath();
uri.set(‘sysparm_m2m_ref’, current.getTableName());
uri.set(‘sysparm_stack’, ‘no’);
action.setRedirectURL(uri.toString(‘sys_m2m_template.do’));
}

Highly appreciate your response.

Regards,

Ashwin

]]>
By: Mark Stanger https://servicenowguru.com/client-scripts-scripting/attach-event-listener-related-list-button/#comment-8948 Fri, 02 Dec 2011 18:26:55 +0000 https://servicenowguru.wpengine.com/?p=4065#comment-8948 In reply to Arlen.

Good catch! There were a couple of issues here. The first was a misplaced parentheses causing the event to be attached to multiple buttons. The second is that Firefox handles this type of thing completely different from every other browser which means it was blowing past our custom event. I’ve updated the code above to handle both of these issues. Please give it a test and let me know if that works better.

]]>
By: Arlen https://servicenowguru.com/client-scripts-scripting/attach-event-listener-related-list-button/#comment-8947 Fri, 02 Dec 2011 14:15:48 +0000 https://servicenowguru.wpengine.com/?p=4065#comment-8947 The idea behind this is great Mark – I can already think of few scenarios where this functionality will be useful :)

Came across few odd experiences:
– Firefox seems to ignore the ‘Alert’ and after a very brief pause continues executing (OK in Chrome)
– The code above seems to execute on any button not just ‘Edit…’

Have you come across this?

]]>