- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 08:46 AM - edited 02-14-2024 08:47 AM
I have a pop-up window which gives the user two options; Cancel and OK.
If they hit cancel I want to simply change the value of a the type field and destroy the GlideDialogWindow.
If they hit OK it will close out the demand record and set all fields to non-mandatory.
I'm pulling over the sys_id for the respective demand but how do you pass back or set form fields from the UI Page?
I attempted with a GlideRecord but it didn't seem to be functioning correctly.
Any help would be appreciated.
onChange Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if(g_form.getValue('type') == 'no_conversion')
{
var dialog = new GlideDialogWindow("no_conversion_popup");
dialog.setSize(600,600);
dialog.setTitle("No Conversion Selected");
dialog.setPreference('sys_id', g_form.getUniqueValue()); //pass current object id
dialog.render(); //Open the dialog
}
}
UI Page Script:
function continueOK() {
alert("OK clicked");
GlideDialogWindow.get().destroy();
}
function continueCancel() {
var gdw = GlideDialogWindow.get(); // attempting to get the sys_id value
var sys_id = gdw.getPreference('sys_id'); // attempting to get the sys_id value
alert("Cancel clicked - sys id is: " + sys_id);
var gr = new GlideRecord('dmn_demand');
gr.addQuery('sys_id', sys_id);
gr.query();
var rc = gr.getRowCount();
alert('rows found is: ' + rc);
GlideDialogWindow.get().destroy();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 01:49 AM
Hi @MBarrott
To achieve your requirements, you need to pass data back and forth between the UI Page and the client script using GlideDialogWindow preferences and then handle the logic accordingly. Here's how you can modify your code:
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Type appropriate comment here, and begin script below
if (g_form.getValue('type') == 'no_conversion') {
var dialog = new GlideDialogWindow("no_conversion_popup");
dialog.setSize(600, 600);
dialog.setTitle("No Conversion Selected");
dialog.setPreference('sys_id', g_form.getUniqueValue()); // Pass current object id
dialog.render(); // Open the dialog
}
}
UI Page Script:
function continueOK() {
var sys_id = g_dialog.getWindow().getPreference('sys_id');
alert("OK clicked - sys id is: " + sys_id);
var gr = new GlideRecord('dmn_demand');
if (gr.get(sys_id)) {
gr.setMandatory(false);
gr.setValue('state', 'Closed');
gr.update();
}
g_dialog.getWindow().destroy();
}
function continueCancel() {
var sys_id = g_dialog.getWindow().getPreference('sys_id');
alert("Cancel clicked - sys id is: " + sys_id);
var gr = new GlideRecord('dmn_demand');
if (gr.get(sys_id)) {
gr.setValue('type', 'other_value');
gr.update();
}
g_dialog.getWindow().destroy(); // Close the GlideDialogWindow
}
In the UI Page script:
- g_dialog.getWindow().getPreference('sys_id') is used to retrieve the sys_id value passed from the client script.
- In the continueOK() function, the demand record with the retrieved sys_id is updated to set all fields to non-mandatory and close out the demand record.
- In the continueCancel() function, the demand record with the retrieved sys_id is updated to change the value of the type field.
Make sure to replace 'dmn_demand' with the correct table name according to your configuration. Additionally, adjust the logic in the continueOK() and continueCancel() functions as per your specific requirements.
Mark as helpful & Accepted Solution !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 01:49 AM
Hi @MBarrott
To achieve your requirements, you need to pass data back and forth between the UI Page and the client script using GlideDialogWindow preferences and then handle the logic accordingly. Here's how you can modify your code:
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Type appropriate comment here, and begin script below
if (g_form.getValue('type') == 'no_conversion') {
var dialog = new GlideDialogWindow("no_conversion_popup");
dialog.setSize(600, 600);
dialog.setTitle("No Conversion Selected");
dialog.setPreference('sys_id', g_form.getUniqueValue()); // Pass current object id
dialog.render(); // Open the dialog
}
}
UI Page Script:
function continueOK() {
var sys_id = g_dialog.getWindow().getPreference('sys_id');
alert("OK clicked - sys id is: " + sys_id);
var gr = new GlideRecord('dmn_demand');
if (gr.get(sys_id)) {
gr.setMandatory(false);
gr.setValue('state', 'Closed');
gr.update();
}
g_dialog.getWindow().destroy();
}
function continueCancel() {
var sys_id = g_dialog.getWindow().getPreference('sys_id');
alert("Cancel clicked - sys id is: " + sys_id);
var gr = new GlideRecord('dmn_demand');
if (gr.get(sys_id)) {
gr.setValue('type', 'other_value');
gr.update();
}
g_dialog.getWindow().destroy(); // Close the GlideDialogWindow
}
In the UI Page script:
- g_dialog.getWindow().getPreference('sys_id') is used to retrieve the sys_id value passed from the client script.
- In the continueOK() function, the demand record with the retrieved sys_id is updated to set all fields to non-mandatory and close out the demand record.
- In the continueCancel() function, the demand record with the retrieved sys_id is updated to change the value of the type field.
Make sure to replace 'dmn_demand' with the correct table name according to your configuration. Additionally, adjust the logic in the continueOK() and continueCancel() functions as per your specific requirements.
Mark as helpful & Accepted Solution !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 06:05 AM
I was actually able to get it working shortly after this your script is very helpful. Thank you for the help!