- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 10:19 AM
Hello Everyone,
I have the following basic form:
On this form, I created a button UI Action that opens a UI Page in a dialog window:
function openUIPage(){
var gdw = new GlideDialogWindow('x_admis_floorplan_Room Picker');
gdw.setTitle('Room Picker');
gdw.setSize(900,900);
gdw.setPreference('table_name', g_form.getTableName());
gdw.setPreference("user_sys_id", g_form.getUniqueValue());
gdw.render();
}
Does anyone know how I can get the Floor ID from the form and pass it to my UI Page so that it can be used in the client script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 02:24 PM
Hi @Andrew158 ,
You can directly use g_form.getValue in the client script of UI page:
var floorID = g_form.getValue('floor_id');
If my answer has helped with your question, please mark it as correct and helpful
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 10:37 AM
To pass the Floor ID from your form to the UI Page and use it in the client script, you can modify your existing code as follows:
Update the button UI Action code:
function openUIPage(){
var floorId = g_form.getValue('floor_id'); // Get the Floor ID from the form field
var gdw = new GlideDialogWindow('x_admis_floorplan_Room Picker');
gdw.setTitle('Room Picker');
gdw.setSize(900, 900);
gdw.setPreference('table_name', g_form.getTableName());
gdw.setPreference('user_sys_id', g_form.getUniqueValue());
gdw.setPreference('floor_id', floorId); // Pass the Floor ID as a preference
gdw.render();
}
- In your UI Page (x_admis_floorplan_Room Picker), you can access the passed Floor ID preference in the client script:
var floorId = g_dialog.getPreference('floor_id');
if (floorId) {
// Use the Floor ID as needed in your client script logic
// For example, you can perform additional operations or make API calls using the floorId
}
By calling g_form.getValue('floor_id'), you can retrieve the value of the 'floor_id' field from your form. Then, when opening the UI Page with GlideDialogWindow, you can set the Floor ID as a preference using gdw.setPreference('floor_id', floorId).
In the UI Page's client script, you can access the preference value using g_dialog.getPreference('floor_id') and use it as needed in your script logic.
Make sure the 'floor_id' field exists on your form and is populated with the Floor ID value before clicking the button UI Action.
Please note that you may need to adjust the field and preference names according to your specific form and UI Page configuration.
Please mark my answer as a solution/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal.
Thanks,
Punit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 02:17 PM
Hello Punit,
Thank you for your response. Unfortunately the solution you proposed is not working for me. I am now getting the reference error "g_dialog is not defined" when launching my UI Page.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 02:24 PM
Hi @Andrew158 ,
You can directly use g_form.getValue in the client script of UI page:
var floorID = g_form.getValue('floor_id');
If my answer has helped with your question, please mark it as correct and helpful
Thanks!