Service Operation Workspace UI Action to show m2m template

Alon Grod
Tera Expert

Hi,

I have a custom table called u_groups_notice with two fields:

1) Task of type Reference to the task table.
2) Group List of type Reference to sys_user_group table.

How can I create a UI Action called 'Notice Groups' in Service Operation Workspace on the incident table that when the user click, he will redirect to m2m template window to edit (add/delete) groups and after clicking save. new record will be add/deleted from u_groups_notice according to the user's action.

When the user clicks on 'Notice Groups' UI Action, he will be redirect to groups collection.

After clicking 'Save', records will be deleted or added to u_groups_notice table with the current incident = task

Screenshot 2023-08-16 at 10.09.24.png

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage
Mega Sage

@Alon Grod Create the UI action on in incident as below

 

jaheerhattiwale_0-1692203029081.png

 

jaheerhattiwale_1-1692203078736.png

 

In workspace section "Format for Configurable Workspace" field is checked.

 

Note: add the tempalte url in the url key shown in image above (after serice-now.com). And replace the sys_id of the incident record in the tempalte url with "g_form.getUniqueValue()"

 

Result:

jaheerhattiwale_2-1692203278269.png

 

Please mark as correct answer if this solved your issue

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

3 REPLIES 3

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @Alon Grod 

Please try below code it will help.

For this you need to create one ui page in which customize slush bucket of group will show

*********************************************************************************************

UI action

Name: Notice Group
Client: true
Form Button: true
OnClick: addNoticeGroups()
Script:

function addNoticeGroups(){ //Open a dialog window to select Groups
var dialog = new GlideDialogWindow('add_notice_groups');
dialog.setTitle('Add Groups Notice');
dialog.setPreference('sysparm_groupQuery', 'active=true');
dialog.setSize(600,900);
dialog.render();
return false;
}
**********************************************************************************************************
UI Page
Name - add_notice_groups
HTML
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<TABLE BORDER="0">
<TR>
<TD>
Please select the groups.
</TD>
</TR>
<TR>
<TD>
<!-- Include the 'ui_slushbucket' UI macro -->
<g:ui_slushbucket/>
</TD>
</TR>
<TR>
<TD align="right">
<!-- Include the 'dialog_buttons_ok_cancel' UI macro -->
<g:dialog_buttons_ok_cancel ok="return continueOK()" cancel="return continueCancel()" ok_type="button" cancel_type="button"/>
</TD>
</TR>
</TABLE>
</j:jelly>
Client script
//Called when the 'OK' button gets clicked
function continueOK(){
//Get the selected values from the right slushbucket
var values = slush.getValues(slush.getRightSelect());
//Get the sys_id of the current record
var taskID = g_form.getUniqueValue();
//Make sure we have at least one selection
if(values == ''){
alert("At least one group must be selected");
return;
}

//Add the group approval records
var ajax = new GlideAjax('GroupSelectAjax');
ajax.addParam('sysparm_name', 'groupsAdd');
ajax.addParam('sysparm_taskID', taskID);
ajax.addParam('sysparm_values', values);
ajax.getXML(addGroupResponse);
}

//Called when we get a response from the 'continueOK' function
function addGroupResponse(){
GlideDialogWindow.get().destroy();
GlideList2.get('').setFilterAndRefresh('');
return false;
}

//Called when the 'Cancel' button gets clicked
function continueCancel(){
//Close the dialog window
GlideDialogWindow.get().destroy();
return false;
}

//Called when the form loads
addLoadEvent(function(){
//Load the groups when the form loads
slush.clear();
var ajax = new GlideAjax('GroupSelectAjax');
ajax.addParam('sysparm_name', 'getGroups');
ajax.getXML(loadResponse);
return false;
});

//Called when we get a response from the 'addLoadEvent' function
function loadResponse(response){
//Process the return XML document and add groups to the left select
var xml = response.responseXML;
var e = xml.documentElement;

var items = xml.getElementsByTagName("item");
if(items.length == 0)
return;

//Loop through item elements and add each item to left slushbucket
for (var i = 0; i < items.length; i++) {
var item = items[i];
slush.addLeftChoice(item.getAttribute('value'), item.getAttribute('text'));
}
}
*******************************************************************************************************************
script include for inserting record in u_groups_notice
Script include name - GroupSelectAjax
Client callable- True
var GroupSelectAjax = Class.create();
GroupSelectAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//Get and return a list of groups (name and sys_id)
getGroups: function() {
var gr = new GlideRecord("sys_user_group");
gr.orderBy('name');
gr.addQuery('active', true);
gr.query();

//Add the available groups to select from
while (gr.next()) {
var item = this.newItem();
item.setAttribute('value', gr.getValue('sys_id'));
item.setAttribute('text', gr.getValue('name'));
}
},

//Take a taskID and group sys_id values and add 'u_group_notice' records
groupsAdd: function() {
var taskID = this.getParameter('sysparm_taskID');
var values = this.getParameter('sysparm_values').split(',');
//Iterate through the group sys_id values
for(x in values){
var rec = new GlideRecord('u_group_notice');
rec.initialize();
rec.u_task_of_type = taskID;
rec.u_group_list_of_type = values[x];
rec.insert();
}
}
});
*****************************************************************************************************************
For Using this ui action in Service Operation workspace please go to the workspace section, checked "Workspace form button" and add  above Ui action code.
Please try and Mark Helpful and Correct if it really helps you.
 

jaheerhattiwale
Mega Sage
Mega Sage

@Alon Grod Create the UI action on in incident as below

 

jaheerhattiwale_0-1692203029081.png

 

jaheerhattiwale_1-1692203078736.png

 

In workspace section "Format for Configurable Workspace" field is checked.

 

Note: add the tempalte url in the url key shown in image above (after serice-now.com). And replace the sys_id of the incident record in the tempalte url with "g_form.getUniqueValue()"

 

Result:

jaheerhattiwale_2-1692203278269.png

 

Please mark as correct answer if this solved your issue

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@jaheerhattiwale How do I know what should be the template url in my scenario ?