logo

NJP

Custom UI Context Menu - Update All functionality

Import · Mar 19, 2019 · article

Hope you guys are having an awesome day. I recently was assigned an Enhancement which had a requirement of providing access to 'Update All' functionality to Asset Management team. But, OOB it would have allowed Asset Management team to see 'Update All' UI Context Menu on all forms.

Rather then providing them this access, I decided to create new similar 'Update All Asset' UI Context Menu which will be available only to asset management team on CI tables.

To achieve this, I firstly created a new UI Context Menu with the name 'Update All Asset'

image

Secondly, select the Table name as 'Configuration Item' and Menu 'List header' and in Condition restrict it to admin role.

image

Finally, my favorite part: Coding

In the 'Action Script' write the following code

runContextAction();

function runContextAction() {
   var url = new GlideURL(g_list.tableName + '_update.do');
   url.addParam('sys_action', 'sysverb_multiple_update');
   url.addParam('sysparm_multiple', 'true');
   url.addParam('sysparm_nostack', 'yes');
   url.addParam('sysparm_query', g_list.getQuery({fixed: true}));
   url.addParam('sysparm_view', g_list.getView());

   var msg = ['Update the entire list?', 'records'];
   var answer = new GwtMessage().getMessages(msg);

   if (!confirm(answer['Update the entire list?'] + " (" + g_list.grandTotalRows + " " + answer['records'] + ")"))
      return;

   window.location = url.getURL();
}

And in onShow script

var query = g_list.getQuery();
var ga_set = new GlideAjax('CIListAjax');
ga_set.addParam('sysparm_name','setQuery');
ga_set.addParam('sysparm_query',query);
ga_set.getXML(setData);
function setData(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
}

The new UI context menu will start appearing on you CI list as soon as you save it.

image

Let me know if you guys face any issues.

Cheers,

Hardit Singh

View original source

https://www.servicenow.com/community/developer-articles/custom-ui-context-menu-update-all-functionality/ta-p/2328011