Workspace Client Script UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 12:01 PM
Hi,
I am trying to fetch all the fields from the current form in "data" and pass it on to the UI page. Currently, we are doing this in UI Macro that is further calling UI Page.
Need your guidance how to write this functionality in Workspace client Script UI action. Appreciate your help, Thanks!!
var datatemp={};
for(var x = 0; x != g_form.elements.length; x++)
{
//getting all fields in the form
datatemp[g_form.elements[x].fieldName]=g_form.getValue(g_form.elements[x].fieldName);
console.log(g_form.elements[x].fieldName+':'+datatemp[g_form.elements[x].fieldName]);
}
var data="'"+JSON.stringify(datatemp)+"'";
var dialog = new GlideDialogWindow("Search Data");
dialog.setTitle("Search Data"); //Set the dialog title
dialog.setPreference("data",data);
dialog.render();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 01:17 PM
Hi Rashim,
To achieve the same functionality in a Workspace client script UI action, you can use the following code:
var datatemp = {};
var formFields = g_form.getEditableFields();
for (var i = 0; i < formFields.length; i++) {
// Getting all editable fields in the form
datatemp[formFields[i]] = g_form.getValue(formFields[i]);
console.log(formFields[i] + ":" + datatemp[formFields[i]]);
}
var data = JSON.stringify(datatemp);
var url = '<your UI Page URL>';
var dialog = new GlideModal(url);
dialog.setTitle('Search Data');
dialog.setPreference('data', data);
dialog.render();
This code first retrieves all the editable fields in the form using g_form.getEditableFields(). It then loops through each field and retrieves the value using g_form.getValue(). The field name and value are stored in the datatemp object.
After that, the datatemp object is converted to a JSON string and passed to the UI page through the setPreference() method.
Finally, a GlideModal is used instead of GlideDialogWindow to open the UI page. This is because GlideDialogWindow is deprecated and GlideModal is the recommended method for opening UI pages in ServiceNow.
Make sure to replace <your UI Page URL> with the actual URL of your UI page.
Please mark my answer correct/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
03-24-2023 01:40 PM - edited 03-24-2023 01:41 PM
Thanks alot Punit for the quick response !!
I have tried GlideModal(url) but it is not working.
I have used it as below:
var url = '/ui_page.do?sys_id=47dc71c3deuyueueyuyeib';
var dialog = new GlideModal(url);
dialog.setTitle('Search Data');
dialog.setPreference('data', data);
dialog.render();
Thanks in advance !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 01:49 PM
Try below instead if that works
var table = 'table_name'; // replace with your table name
var sysId = '47dc71c3deuyueueyuyeib'; // replace with your record's sys_id
var view = 'form'; // replace with the view you want to display (e.g. form, list, etc.)
var gm = new GlideModalForm(table, sysId, view);
gm.setTitle('Search Data');
gm.render();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 01:56 PM - edited 03-24-2023 01:56 PM
Actually we are trying to send data to the UI Page. We can not use the table name in this. I have tried the below code, its showing the window but data is not getting passed. Not sure, if we are not passing data in the URL correctly. Please check this one if you can. Appreciate your help !!
g_modal.showFrame({
title: 'Search Data',
url: '/ui_page.do?sys_id=47dc71c3db7af3806yuytyutu19fb?data=' + data,
size: 'lg'
});