UI action button should open the UI page .

instance
Tera Contributor

 

HTML script

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
     <g:ui_form>
    <table>
        
        <tr>
                  <td style="width:25%">
            <g:form_label>
            Assignment Group: 
                </g:form_label>     
                  </td>
          <td style="width:60%">
            <g:ui_reference name="grp_ref" id="grp_ref"  table="sys_user_group"  />
                   </td>
                </tr>
        <tr>
                   <td style="width:25%">
            <g:form_label>
            Assigned to: 
            </g:form_label>
                   </td>
            <td style="width:60%">
                      <g:ui_reference name="user_ref" id="user_ref"  table="sys_user"  />
                    </td>
                </tr>
                <tr>
        <td style="width:25%">
            <g:form_label>
            Work Notes: 
            </g:form_label>
                 </td>
        <td style="width:60%"> 
                 <input type="text" aria-label="Print your name" name="my_name" id="my_name" maxlength="25"/>   
                </td>
        </tr>
        <tr>
                     <td>
                       <g:dialog_buttons_ok_cancel ok_id="submitData" ok="return continueOK()" ok_type="button" ok_text="${gs.getMessage('Okay')}" ok_style_class="btn btn-primary" cancel_type="button" cancel_id="cancelData" cancel_style_class="btn btn-default" cancel="return continueCancel()"/>
                    </td>
               </tr>
    </table>
    </g:ui_form>
</j:jelly>
 
Client Script:
function continueOK() {
    alert("OK clicked");
    var gdw = GlideDialogWindow.get();
    var name =gel('my_name').value;
    var user = gel('user_ref').value;
    var cat = gel('grp_ref').value;
    g_form.save();
    GlideDialogWindow.get().destroy();
}
function continueCancel() {
    GlideDialogWindow.get().destroy();
}
 
In the UI action Button
 
 
On clicking the Button in the Service Operations Workspace the Button is not poping  out the ui page.
what error in the script ?
1 ACCEPTED SOLUTION

Hi @instance  ,

 

Try using the following scripts as is.

 

UI Page:

Name: re_assign_custom

 

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">
<g:evaluate var="jvar_isNextPg" expression="RP.getParameterValue('sysparm_next_pg')"/>
	<j:if test="${jvar_isNextPg == 'true'}">
		<style>
			.no_next {
				display: none !important;
			}
		</style>
	</j:if>
	<style>
		body {
			overflow-x: hidden;
		}
		#incident-reassign-form {
			overflow: hidden;
		}
		.form-horizontal {
			margin-top: 5px;
			margin-bottom: 20px;
		}
		.reassign-modal-textarea {
			resize: vertical;
			min-height: 120px
		}
		#work-notes-wrapper .required-marker{
			display: inline-block;
		}
		#dialog_buttons .btn{
			margin-left: 10px;
			padding-left: 15px;
			padding-right: 15px;
			text-align: right;
		}
	
		#page_timing_div {
			display:none !important;
		}
	</style>
	<script>
		var config = {
			workspace: '${JS_STRING:RP.getParameterValue('sysparm_workspace')}' == 'true'
		};
		var iframeMsgHelper = (function () {
			function createPayload(action, modalId, data) {
					return {
						messageType: 'IFRAME_MODAL_MESSAGE_TYPE',
						modalAction: action,
						modalId: modalId,
						data: (data ? data : {})
					};
				}

				function pm(window, payload) {
					if (window.parent === window) {
						console.warn('Parent is missing. Is this called inside an iFrame?');
						return;
					}
					window.parent.postMessage(payload, location.origin);
				}

				function IFrameMessagingHelper(window) {
					this.window = window;
					this.src=location.href;
					this.messageHandler = this.messageHandler.bind(this);
					this.window.addEventListener('message', this.messageHandler);
				}

				IFrameMessagingHelper.prototype.messageHandler = function (e) {
					if (e.data.messageType !== 'IFRAME_MODAL_MESSAGE_TYPE' || e.data.modalAction !== 'IFRAME_MODAL_ACTION_INIT') {
						return;
					}
					this.modalId = e.data.modalId;
				};

				IFrameMessagingHelper.prototype.confirm = function (data) {
					var payload = createPayload('IFRAME_MODAL_ACTION_CONFIRMED', this.modalId, data);
					pm(this.window, payload);
				};

				IFrameMessagingHelper.prototype.cancel = function (data) {
					var payload = createPayload('IFRAME_MODAL_ACTION_CANCELED', this.modalId, data);
					pm(this.window, payload);
				};

				return new IFrameMessagingHelper(window);
			}());

	</script>
<div id="incident-reassign-form">
<div class="form-horizontal no_next">
	 <table>
        <tr>
			<td style="width:25%">
				<g:form_label>Assignment Group: </g:form_label>     
			</td>
			<td style="width:60%">
				<g:ui_reference name="grp_ref" id="grp_ref"  table="sys_user_group"  />
			</td>
		 </tr>
		 <tr></tr>
		 <tr>
			 <td style="width:25%">
				 <g:form_label>
					 Assigned to: 
				 </g:form_label>
			 </td>
			 <td style="width:60%">
				 <g:ui_reference name="user_ref" id="user_ref"  table="sys_user"  />
			 </td>
		 </tr>
		 <tr>
			 <td style="width:25%">
				 <g:form_label>
					 Work Notes: 
				 </g:form_label>
			 </td>
			 <td style="width:60%"> 
                 <textarea required="true" class="form-control reassign-modal-textarea" id="inc-reassign-work-notes" type="text" oninput="reassignModal.workNotesOnChange()" onchange="reassignModal.workNotesOnChange()"></textarea>
			 </td>
        </tr>
	</table>
</div>
<div id="dialog_buttons" class="clearfix pull-right no_next">
		<button type="button" class="btn btn-default" onclick="reassignModal.close()" title="${gs.getMessage('Close the dialog')}">${gs.getMessage('Cancel')}</button>
		<button type="button" class="btn btn-primary disabled" aria-disabled="true" id="inc-reassign-button" title="${gs.getMessage('Propose Major Incident')}" onclick="reassignModal.assign()">${gs.getMessage('Re Assign')}</button>
</div>
</div>
</j:jelly>

 

Client Script:

 

addLoadEvent(function() {
	(function(global) {
		var workNotes = $("inc-reassign-work-notes");		
		var reassignBtn = $('inc-reassign-button');
		workNotes.focus();
		var dialog, resizeObserver;
		if(!config.workspace) {
			dialog = GlideModal.prototype.get("sn_major_inc_mgmt_mim_propose");

          var currentWorkNotes = dialog.getPreference('WORK_NOTES');
          if(currentWorkNotes) {
              workNotes.value = currentWorkNotes;
              workNotesOnChange();
          }
          var currentBusinessImpact = dialog.getPreference('BUSINESS_IMPACT');
          if(currentBusinessImpact)
              businessImpact.value = currentBusinessImpact;
        } else {
			var modalTextAreas = document.querySelectorAll(".propose-modal-textarea");
			var iframeStyle = window.frameElement.style;
			var formContainer = $("mim-propose-form");
			resizeObserver = new ResizeObserver(function(entries) {
				iframeStyle.height = formContainer.offsetHeight + 5 + "px";
			});
			for(var i=0; i < modalTextAreas.length; i++) {
				resizeObserver.observe(modalTextAreas[i]);
			}
		}
		function _debounce(func, wait, immediate) {
			var timeout;
			return function() {
				var context = this,
					args = arguments;
				var later = function() {
					timeout = null;
					if (!immediate) func.apply(context, args);
				};
				var callNow = immediate && !timeout;
				clearTimeout(timeout);
				timeout = setTimeout(later, wait);
				if (callNow) func.apply(context, args);
			};
		}

		function workNotesOnChange() {
			if (!workNotes.value.trim()) {
				reassignBtn.addClassName('disabled');
				reassignBtn.writeAttribute('aria-disabled', true);
			} else {
				reassignBtn.removeClassName('disabled');
				reassignBtn.writeAttribute('aria-disabled', false);
			}
		}

		function assign() {
			if (!reassignBtn.hasClassName('disabled')) {
				var msg = getMessage("Re-Assigned incident");
				var notes = workNotes.value.trim();
				var user = gel('user_ref').value;
				var group = gel('grp_ref').value;
				if(!config.workspace) {
					g_form.getControl('work_notes').value = msg + "\n" + notes;
					if (user)
						g_form.setValue('assigned_to', user);
					if (group)
						g_form.setValue('assignment_group', group);
					close();
					gsftSubmit(null, g_form.getFormElement(), 'sysverb_inc_reassign');
				}else {
					iframeMsgHelper.confirm({
						msg: msg,
						workNotes: notes,
						assignedTo: user,
						assignmentGroup: group
					});
				}
			}
		}

		function close() {
			if(!config.workspace) {
				dialog.destroy();
			} else {
				resizeObserver.disconnect();
				window.location.href = window.location.href + '&sysparm_next_pg=true';
			}
		}
		global.reassignModal = {
			assign: assign,
			close: close,
			workNotesOnChange: _debounce(workNotesOnChange, 200) // Only execute when left idle for 200 ms
		};
	})(window);
});

 

UI Action

Script:

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

//Server-side code
function proposeMICOnConfirmation() {
	current.update();
	gs.addInfoMessage(gs.getMessage('{0} has been re assigned', current.getDisplayValue()));
	action.setRedirectURL(current);
}

 

Workspace Client Script:

 

function onClick(g_form) {
	
	function proposeMIC(data) {
		var workNotes = data.msg + "\n" + data.workNotes;
		var notes = g_form.getValue('work_notes') + ' ' + workNotes;
		var user = data.assignedTo;
		var group = data.assignmentGroup;
		g_form.setValue('work_notes', notes.trim());
		g_form.setValue('assigned_to', user);
		g_form.setValue('assignment_group', group);
		g_form.submit('reassign_inc_ws');
	}
	
    var url = "/re_assign_custom.do?sysparm_stack=no&sysparm_workspace=" + true;
    g_modal.showFrame({
        title: getMessage("Propose Major Incident"),
        url: url,
        size: 'lg',
        autoCloseOn: 'URL_CHANGED',
        callback: function(ret, data) {
            if (ret)
                proposeMIC(data);
        }
    });
}

 

 

AnveshKumarM_0-1680593775878.png

AnveshKumarM_1-1680593808880.png

 

AnveshKumarM_2-1680593836586.png

 

Thanks,

Anvesh

Thanks,
Anvesh

View solution in original post

9 REPLIES 9

DrewW
Mega Sage
Mega Sage

Sounds like your UI Action is a client side one so have you just tried using 

window.open(URL, name, specs, replace);

 and make sure that all your parameters are added to the URL?

Oh and you may need to use top.window.open

Anil Lande
Kilo Patron

Hi,

to open pop up in workspace UI we need to use different way.

Check below links for similar solutions:

1. How to use UI Actions in Workspaces 

2. https://www.servicenow.com/community/developer-forum/open-pop-up-in-workspace-using-ui-action/m-p/24...

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

you should be able to find the steps on 

https://www.servicenow.com/community/next-experience-articles/how-to-use-ui-actions-in-workspaces/ta...

 

you just need to change the field types and it should work fine.

Please give a try and share if you face any issue.

UI Page will not work in workspace UI.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande