Alternative to the GlideModal setPreference() method in Workspaces ... ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 01:51 AM
Hello all,
Bit of an issue here - I'm trying to modify a copied version of the OOTB Incident UI Action "Propose Major Incident".
The ask is for one of the string field which pop up in the GlideModal, "Business Impact", to prepopulate with a series of text prompts for the end user. In Core UI this is fine; just edit the g_form.setPreference() to include the new string, fine.
In Workspaces I'm having more trouble however ... As far as I'm aware you can't use GlideModal in Workspaces, and instead I'm having to use g_modal ... The problem being that in the documentation, in g_modal.openFrame() I can't see anything resembling the setPreference() method ... Does anyone have any ideas as to how I could resolve this?
Many thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 02:43 AM
Thanks Ankur but I'm still a bit confused, I don't suppose you could clarify please? This is the mim_propose OOTB UI Page 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: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;
}
#mim-propose-form {
overflow: hidden;
}
.form-horizontal {
margin-top: 5px;
margin-bottom: 20px;
}
.propose-modal-textarea {
resize: vertical;
min-height: 120px
}
#dialog_buttons .btn{
margin-left: 10px;
padding-left: 15px;
padding-right: 15px;
text-align: right;
}
#work-notes-wrapper .required-marker{
display: inline-block;
}
#work-notes-wrapper label{
overflow-wrap: break-word;
}
#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="mim-propose-form">
<div class="form-horizontal no_next">
<div class="form-group" id="work-notes-wrapper">
<label class="col-sm-2 control-label" for="mim-propose-work-notes">
<span mandatory="true" class="required-marker"></span>
${gs.getMessage('Work notes')}
</label>
<div class="col-sm-10">
<textarea required="true" class="form-control propose-modal-textarea" id="mim-propose-work-notes" type="text" oninput="proposeModal.workNotesOnChange()" onchange="proposeModal.workNotesOnChange()"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="mim-propose-business-impact">${gs.getMessage('Business Impact')}</label>
<div class="col-sm-10">
<textarea class="form-control propose-modal-textarea" name="mim-propose-business-impact" id="mim-propose-business-impact"></textarea>
</div>
</div>
</div>
<div id="dialog_buttons" class="clearfix pull-right no_next">
<button type="button" class="btn btn-default" onclick="proposeModal.close()" title="${gs.getMessage('Close the dialog')}">${gs.getMessage('Cancel')}</button>
<button type="button" class="btn btn-primary disabled" aria-disabled="true" id="mim-propose-button" title="${gs.getMessage('Propose Major Incident')}" onclick="proposeModal.propose()">${gs.getMessage('Propose')}</button>
</div>
</div>
</j:jelly>
And here is the OOTB "Propose Major Incident" 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 bi = g_form.getValue('business_impact') + ' "hello world"' + data.businessImpact;
g_form.setValue('work_notes', notes.trim());
g_form.setValue('business_impact', bi.trim());
g_form.submit('sysverb_mim_propose');
}
function openPopup() {
var missingMandatoryFields = getMissingFields();
if (missingMandatoryFields.length > 0) {
g_form.save();
} else {
if (!g_form.getControl('work_notes')) {
getMessage('Cannot propose major incident as "Worknotes" is not visible', function(msg) {
g_form.addErrorMessage(msg);
});
return false;
}
var url = "/sn_major_inc_mgmt_mim_propose.do?sysparm_stack=no&sysparm_workspace=" + true;
getMessage('Propose Major Incident', function(msg) {
g_modal.showFrame({
title: msg,
url: url,
size: 'lg',
autoCloseOn: 'URL_CHANGED',
callback: function(ret, data) {
if (ret)
proposeMIC(data);
}
});
});
}
}
function filterForMissingMandatoryFields(field) {
if (g_form.isMandatory(field)) {
return !g_form.getValue(field);
}
}
function getMissingFields() {
var fieldList = g_form.getFieldNames();
//return only mandatory fields that have no value
return fieldList.filter(filterForMissingMandatoryFields);
}
openPopup();
}
I've tried editing it the way you did in your screenshots but it doesn't seem to be working for me; would you mind pointing out where in these scripts I edit to add the string? Greatly appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:07 AM
you need to pass some static text from workspace client script to UI page?
would be nice if you share screenshots, value to be passed from where and to where?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:39 AM
Hi Ankur, I've just added some screenshots if you have time 🙂 (in a reply to your other comment), thanks!