- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2017 11:20 AM
Is it possible to start with a UI Action on the sc_task form, use the GlideDialogWindow to gather information and save that information to the parent RITM? I have used the examples for creating a GlideDialogWindow so I have the popup box to collect the information but not sure how to write it to the parent RITM. I know the client script on the UI page isn't correct when I say g_form.setValue because I'm on the wrong form since I'm on the sc_task. Is there a way to redirect to the parent RITM or just update the RITM from the sc_task form?
I am hoping to give our fulfillers a way to cancel a request from the task if need be while still gathering the same information as if they were cancelling it from the RITM for reporting purposes.
UI Action script
function commentsDialog() {
//Get the values to pass into the dialog
var tsk = g_form.getUniqueValue();
var ritm = g_form.getValue("request_item");
var reason = g_form.getValue("ritm.u_reason");
var comments_text = g_form.getValue("ritm.comments");
var short_text = g_form.getValue("ritm.short_description");
//Initialize and open the dialog
var dialog = new GlideDialogWindow("ritm_reason_dialog"); //Instantiate the dialog containing the UI Page 'add_comments_dialog'
dialog.setTitle("What is the reason for cancelling this request item?"); //Set the dialog title
dialog.setPreference("reason", reason); //Pass the reason value into the dialog
dialog.setPreference("comments_text", comments_text); //Pass the comments into the dialog
dialog.setPreference("short_text", short_text); //Pass in a short description for use in the dialog
dialog.setPreference("ritm", ritm); //Pass in a request item sys_id for use in the dialog
dialog.setPreference("tsk", tsk); //Pass the task sys_id into the dialog
dialog.render(); //Open the dialog
}
UI Page
HTML
<g:ui_form>
<!-- Get the values from dialog preferences -->
<g:evaluate var="jvar_tsk"
expression="RP.getWindowProperties().get('tsk')" />
<g:evaluate var="jvar_ritm"
expression="RP.getWindowProperties().get('ritm')" />
<g:evaluate var="jvar_short_text"
expression="RP.getWindowProperties().get('short_text')" />
<g:evaluate var="jvar_reason"
expression="RP.getWindowProperties().get('reason')" />
<g:evaluate var="jvar_comments_text"
expression="RP.getWindowProperties().get('comments_text')" />
<!-- Set up form fields and labels -->
<table width="100%">
<tr id="description_row" valign="top">
<td colspan="2">
<!-- Short description value used as a label -->
${jvar_short_text}
</td>
</tr>
<tr>
<td>
<!-- Reason dropdown field from the RITM -->
<g:ui_choicelist name="reason" table="sc_req_item" field="u_reason"
value="${jvar_reason}" mandatory="true" />
</td>
</tr>
<br>
</br>
<tr>
<td>
<!-- Comments text field (Contains comments from originating record as a default) -->
<g:ui_multiline_input_field name="dialog_comments" id="dialog_comments" label="Additional comments"
value="${jvar_comments_text}" mandatory="true" />
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr id="dialog_buttons">
<td colspan="2" align="right">
<!-- Add OK/Cancel buttons. Clicking OK calls the validateComments script -->
<g:dialog_buttons_ok_cancel ok="return validateComments()" ok_type="button" cancel_type="button" />
</td>
</tr>
</table>
</g:ui_form>
Client Script
function validateComments() {
//This script is called when the user clicks "OK" in the dialog window
//Make sure there are comments to submit
var tsk = g_form.getUniqueValue();
var tskritm = g_form.getValue('request_item');
var reason = gel("reason").value;
var comments = gel("dialog_comments").value;
var ga = new GlideAjax('validateComments'); //Call script include to escape text
ga.addParam('sysparm_name', 'validateComments');
ga.addParam('sysparm_comments', comments);
ga.getXMLWait();
comments = ga.getAnswer(); //Set comments to escaped text
comments = trim(comments);
if (comments == "") {
//If comments are empty, alert the user and stop submission
alert(tskritm);
alert("Please select a reason and enter your comments before submitting.");
return false;
}
If there are comments, close the dialog window and submit them
GlideDialogWindow.get().destroy(); //Close the dialog window
//Set fields on parent RITM
g_form.setValue("comments", comments); //Set the "Comments" field with comments in the dialog
g_form.setValue("state", '99');
g_form.setValue("u_reason", reason);
g_form.setValue("stage", "Request Canceled");
g_form.save();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2017 11:29 AM
Hi April,
You can't actually set the values on another record using client side g_form. You could, however, use GlideAjax from the client side code in your ui page. You could pass it the sysID of the RITM then in the script include do the actual updating of the ritm record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2017 02:41 PM
I would add some logging to your script include to confirm that it's getting called and that it is setting values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2017 08:56 PM
Thank you so much for your guidance and expertise Brad!
You were correct in that my script include wasn't being called. Found the error and everything is working fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2023 03:26 AM
Hi Brad,
I trust this msg finds you well.
I wonder if you could point me in the right direction.
I am trying to simplify the way staff enter the 'time worked' within incidents. Rather than scrolling down to the related list and add a record i decided to do it differently.
I want them to click a button (UI Action) which would call a popup (UI Page). The ui page will collect the details and insert a record in the 'task_time_worked' table.
is this possible?
So far i created the UI Action that calls the UI Page