UI Page g_form.save() doesn't commit changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2018 08:09 AM
Hi,
I am currently trying to set a choice field on the work order task to an option selected by the user in a GlideDialogWindow which is generated from a UI page.
I need to set the 'Clear code' on the work order task to the selected 'Clear code' value found in the form below.
However the work order task is set to 'Closed incomplete' successfully without committing the changes to the 'Clear code' value even though I can see the field being set before the work order task is updated and refreshed.
I have tried using both g_form.save() and gsftSubmit(gel('sysverb_update_and_stay')) but no luck. Appreciate any assistance.
Here is what I'm working with.
UI Page HTML
<g:ui_form>
<j:set var="task_id" value="${RP.getWindowProperties().get('sys_id')}" />
<input type="hidden" name="cancelled" id="cancelled" value="false" />
<input type="hidden" name="task_id" id="task_id" value="${RP.getWindowProperties().get('sys_id')}" />
<input type="hidden" name="state_flow" id="state_flow" value="${RP.getWindowProperties().get('state_flow_id')}" />
<j:set var="cancelled" value="false" />
<j:set var="jvar_work_notes" value="${RP.getWindowProperties().get('work_notes')}" />
<j:set var="jvar_dependent_value" value="${RP.getWindowProperties().get('dependent_value')}" />
<style>
#task_close_incomplete .left {
max-width: 60px;
}
#task_close_incomplete #yesno {
width: 98%
}
HTML[data-doctype=true] #task_close_incomplete #yesno {
width: 100%
}
</style>
<table id="task_close_incomplete" width="100%">
<colgroup>
<col />
<col />
</colgroup>
<tr>
<td class="left">
<span title="${gs.getMessage('Mandatory - must be populated before Submit')}" mandatory="true" oclass="mandatory" style="background-color:#C00;color:#C00;margin-right:3px;margin-left:1px;">I</span>
<label for="clear_code">${gs.getMessage("Clear code")}</label>
</td>
<td align="right" style="padding: 0 0 4px 8px;">
<select name="clear_code" id="clear_code" class="form-control select2">
<option />
<g2:evaluate var="jvar_item" expression="var gr = new GlideRecord('sys_choice');gr.addQuery('name', 'wm_task');gr.addQuery('element', 'u_clear_code');gr.addQuery('dependent_value', '${jvar_dependent_value}');gr.addQuery('inactive', 'false');gr.query();" />
<j2:while test="$[gr.next()]">
<option value="$[gr.getValue('value')]">$[gr.getValue('label')]</option>
</j2:while>
</select>
</td>
</tr>
<tr>
<td colspan="2" id="clear_code_error" style="display: none">
<img src='images/outputmsg_error.gifx' alt=''/>${gs.getMessage("Please provide a clear code")}
</td>
</tr>
</table>
</g:ui_form>
UI Page Client Script
function submitCancel(){
var c = gel('cancelled');
c.value = "true";
GlideDialogWindow.get().destroy();
return false;
}
function submitChanges() {
var taskId = gel('task_id').value;
var selection = gel('yesno').value;
if (selection.length < 1) {
document.getElementById('yesno_error').style.backgroundColor="#FFEBE8";
document.getElementById('yesno_error').style.display="block";
return false;
}
else{
document.getElementById('yesno_error').style.display="none";
}
var clearCode = gel('clear_code').value;
if (clearCode.length < 1) {
document.getElementById('clear_code_error').style.backgroundColor="#FFEBE8";
document.getElementById('clear_code_error').style.display="block";
return false;
}
else{
document.getElementById('clear_code_error').style.display="none";
g_form.setValue('u_clear_code', clearCode); }
var notes = gel('work_notes_update').value.replace(/^\s+|\s+$/g,''); // trim
if (notes.length < 1) {
document.getElementById('work_notes_error').style.backgroundColor="#FFEBE8";
document.getElementById('work_notes_error').style.display="block";
return false;
}
else{
document.getElementById('work_notes_error').style.display="none";
}
g_form.clearValue("work_notes");
g_form.save();
GlideAjax.disableSessionMessages();
return true;
}
- Labels:
-
Field Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2018 09:20 AM
Hi ,
The user in below link faced similar issue have a look if it helps.
https://community.servicenow.com/community?id=community_question&sys_id=e1c08b65db98dbc01dcaf3231f96198d
Mark my ANSWER as CORRECT and HELPFUL if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2018 03:40 AM
Unfortunately even though this resolves the issue around submitting the clear code field, it brings about another issue where the work order task is not moved to the state of 'Closed incomplete'. I imagine the g_form.save() action is now abruptly ending any processing that happens in my processing script where a call is made to the appropriate 'sf_state_flow' table to correctly update the state of the WOT.
Processing Script
if ('false' == cancelled) {
var taskToClone = new GlideRecord("sm_task");
if (taskToClone.get(task_id)) {
var className = taskToClone.sys_class_name;
taskToClone = new GlideRecord(className);
taskToClone.get(task_id);
var clonedTask;
if (GlidePluginManager.isActive('com.snc.wm_questionnaire')) {
var gr = new GlideRecord("sf_state_flow");
gr.get(state_flow);
taskToClone.state = gr.end_text;
if (new FSMQuestionnaireHelper().pendingQuestionareExist(taskToClone)) {
response.sendRedirect("sm_task.do?sys_id=" + taskToClone.sys_id);
gs.addErrorMessage(gs.getMessage('Please complete mandatory questionnaires.'));
} else {
taskToClone = new GlideRecord(className);
taskToClone.get(task_id);
if (yesno == 'y') {
// Clone the current task
var clonedTask = new SMTask().cloneTask(taskToClone, true);
getWorkNote(clonedTask);
}
taskToClone.work_notes = work_notes_update;
new global.StateFlow().processFlow(taskToClone, state_flow, 'manual');
if (yesno == 'y') {
// redirect to the newly cloned task
response.sendRedirect("sm_task.do?sys_id=" + clonedTask.sys_id);
gs.addInfoMessage(gs.getMessage("Cloned from {0}", taskToClone.getValue('number')));
} else {
response.sendRedirect("sm_task.do?sys_id=" + taskToClone.sys_id);
}
}
} else {
if (yesno == 'y') {
// Clone the current task
var clonedTask = new SMTask().cloneTask(taskToClone, true);
getWorkNote(clonedTask);
}
taskToClone.work_notes = work_notes_update;
new global.StateFlow().processFlow(taskToClone, state_flow, 'manual');
if (yesno == 'y') {
// redirect to the newly cloned task
response.sendRedirect("sm_task.do?sys_id=" + clonedTask.sys_id);
gs.addInfoMessage(gs.getMessage("Cloned from {0}", taskToClone.getValue('number')));
} else
response.sendRedirect("sm_task.do?sys_id=" + taskToClone.sys_id);
}
}
}
// ACN added - copy reason for follow up to cloned task
function getWorkNote(clone) {
clone.work_notes = "Reason for incomplete closure of original task:\n" + work_notes_update;
clone.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2020 05:16 AM
Hello,
I have the same problem,
the manual changes made on the form before hitting the UI Action(which triggers UI page) are not saving to the database although we have the g_form.save() in the UI Page client script.
The processing script is working fine though.
were you able to resolve this issue?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2020 05:27 AM
Hi,
Please go through below link.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0743833
Mark it correct and helpful.
Thanks
Bhagyashri Sorte.