<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Workspace Client Script UI action in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516509#M980388</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need your guidance how to write this functionality in Workspace client Script UI action.&amp;nbsp; Appreciate your help, Thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var datatemp={};&lt;BR /&gt;for(var x = 0; x != g_form.elements.length; x++)&amp;nbsp;&lt;BR /&gt;{&lt;BR /&gt;//getting all fields in the form&lt;BR /&gt;datatemp[g_form.elements[x].fieldName]=g_form.getValue(g_form.elements[x].fieldName);&lt;BR /&gt;console.log(g_form.elements[x].fieldName+':'+datatemp[g_form.elements[x].fieldName]);&lt;BR /&gt;}&lt;BR /&gt;var data="'"+JSON.stringify(datatemp)+"'";&lt;BR /&gt;&lt;BR /&gt;var dialog = new GlideDialogWindow("Search Data");&lt;BR /&gt;dialog.setTitle("Search Data"); //Set the dialog title&lt;BR /&gt;dialog.setPreference("data",data);&lt;BR /&gt;dialog.render();&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Mar 2023 19:01:30 GMT</pubDate>
    <dc:creator>Rashim Walia</dc:creator>
    <dc:date>2023-03-24T19:01:30Z</dc:date>
    <item>
      <title>Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516509#M980388</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need your guidance how to write this functionality in Workspace client Script UI action.&amp;nbsp; Appreciate your help, Thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var datatemp={};&lt;BR /&gt;for(var x = 0; x != g_form.elements.length; x++)&amp;nbsp;&lt;BR /&gt;{&lt;BR /&gt;//getting all fields in the form&lt;BR /&gt;datatemp[g_form.elements[x].fieldName]=g_form.getValue(g_form.elements[x].fieldName);&lt;BR /&gt;console.log(g_form.elements[x].fieldName+':'+datatemp[g_form.elements[x].fieldName]);&lt;BR /&gt;}&lt;BR /&gt;var data="'"+JSON.stringify(datatemp)+"'";&lt;BR /&gt;&lt;BR /&gt;var dialog = new GlideDialogWindow("Search Data");&lt;BR /&gt;dialog.setTitle("Search Data"); //Set the dialog title&lt;BR /&gt;dialog.setPreference("data",data);&lt;BR /&gt;dialog.render();&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 19:01:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516509#M980388</guid>
      <dc:creator>Rashim Walia</dc:creator>
      <dc:date>2023-03-24T19:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516549#M980400</link>
      <description>&lt;P&gt;Hi Rashim,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;To achieve the same functionality in a Workspace client script UI action, you can use the following code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var datatemp = {};
var formFields = g_form.getEditableFields();
for (var i = 0; i &amp;lt; 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 = '&amp;lt;your UI Page URL&amp;gt;';
var dialog = new GlideModal(url);
dialog.setTitle('Search Data');
dialog.setPreference('data', data);
dialog.render();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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 &amp;lt;your UI Page URL&amp;gt; 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
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 20:17:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516549#M980400</guid>
      <dc:creator>Punit S</dc:creator>
      <dc:date>2023-03-24T20:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516556#M980405</link>
      <description>&lt;P&gt;Thanks alot Punit for the quick response !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried GlideModal(url) but it is not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used it as below:&lt;/P&gt;&lt;P&gt;var url = '/ui_page.do?sys_id=47dc71c3deuyueueyuyeib';&lt;BR /&gt;var dialog = new GlideModal(url);&lt;BR /&gt;dialog.setTitle('Search Data');&lt;BR /&gt;dialog.setPreference('data', data);&lt;BR /&gt;dialog.render();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance !!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 20:41:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516556#M980405</guid>
      <dc:creator>Rashim Walia</dc:creator>
      <dc:date>2023-03-24T20:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516564#M980410</link>
      <description>&lt;P&gt;Try below instead if that works&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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();&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 20:49:42 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516564#M980410</guid>
      <dc:creator>Punit S</dc:creator>
      <dc:date>2023-03-24T20:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516567#M980411</link>
      <description>&lt;P&gt;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 !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;g_modal.showFrame({&lt;BR /&gt;&lt;BR /&gt;title: 'Search Data',&lt;BR /&gt;url: '/ui_page.do?sys_id=47dc71c3db7af3806yuytyutu19fb?data=' + data,&lt;BR /&gt;size: 'lg'&lt;BR /&gt;});&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 20:56:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516567#M980411</guid>
      <dc:creator>Rashim Walia</dc:creator>
      <dc:date>2023-03-24T20:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516574#M980413</link>
      <description>&lt;P&gt;Here's another way to do it.&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a UI page and add the following code to it:&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="UTF-8"&amp;gt;
  &amp;lt;title&amp;gt;My UI Page&amp;lt;/title&amp;gt;
  &amp;lt;script&amp;gt;
    function passData() {
      var data = {
        "field1": "value1",
        "field2": "value2"
      };
      var url = "/nav_to.do?uri=incident.do?sys_id=-1&amp;amp;sysparm_query=";
      var encodedData = encodeURIComponent(JSON.stringify(data));
      url += encodedData;
      window.location.href = url;
    }
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;h1&amp;gt;My UI Page&amp;lt;/h1&amp;gt;
  &amp;lt;button onclick="passData()"&amp;gt;Pass Data&amp;lt;/button&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code defines a function passdata( ) that creates a data object and encodes it as a URL parameter. When the user clicks the "Pass Data" button, the function sets the current URL to the URL of a new incident form with the encoded data added as a parameter.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a UI action that opens the UI page you just created:&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function() {
  var url = '/sys_ui_page.do?sys_id=&amp;lt;UI_PAGE_SYS_ID&amp;gt;';
  action.setRedirectURL(url);
})();
​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Replace &amp;nbsp;&amp;lt;UI_PAGE_SYS_ID&amp;gt;with the sys ID of the UI page you created in step 1.&lt;/P&gt;&lt;P&gt;When the user clicks the UI action, the UI page will open, and the "Pass Data" button will be visible. When the user clicks the "Pass Data" button, they will be redirected to a new incident form with the data encoded as a parameter in the URL. You can retrieve this data in the new form using a script like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var urlParams = new URLSearchParams(window.location.search);
var encodedData = urlParams.get('sysparm_query');
var data = JSON.parse(decodeURIComponent(encodedData));
​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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​&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 21:26:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516574#M980413</guid>
      <dc:creator>Punit S</dc:creator>
      <dc:date>2023-03-24T21:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516576#M980415</link>
      <description>&lt;P&gt;Actually we already have an existing UI Page that is consuming "data" from the existing Macro. But Macros don't work for the Agent workspace thats why we have created a UI action.&lt;/P&gt;&lt;P&gt;We simply need to pass the "Data" component that has string of all the fields already in the UI action. I guess we just need the correct way of passing the "data" component in the URL.&lt;/P&gt;&lt;P&gt;Below method for the passing the "data" component is not working. Do you know any way to get it passed:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;g_modal.showFrame({&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;title: 'Search Data',&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;url: '/ui_page.do?sys_id=47dc71c3db7af3806yuytyutu19fb?data=' + data,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;size: 'lg'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;});&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 21:33:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516576#M980415</guid>
      <dc:creator>Rashim Walia</dc:creator>
      <dc:date>2023-03-24T21:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516578#M980417</link>
      <description>&lt;P&gt;&lt;SPAN&gt;To pass data from a UI action to a UI page in ServiceNow, you can use the &lt;/SPAN&gt;urlParm()&lt;SPAN&gt; function to encode the data and include it as a URL parameter. Here's an example of how you can modify the &lt;/SPAN&gt;g_modal.showFrame()&lt;SPAN&gt; code to pass the "data" component as a URL parameter:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;To pass data from a UI action to a UI page in ServiceNow, you can use the urlParm() function to encode the data and include it as a URL parameter. Here's an example of how you can modify the g_modal.showFrame() code to pass the "data" component as a URL parameter:
g_modal.showFrame({
    title: 'Search Data',
    url: '/ui_page.do?sys_id=47dc71c3db7af3806yuytyutu19fb&amp;amp;' + urlParm({ data: data }),
    size: 'lg'
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;EM&gt;&lt;STRONG&gt;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​&lt;/STRONG&gt;&lt;/EM&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 21:44:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516578#M980417</guid>
      <dc:creator>Punit S</dc:creator>
      <dc:date>2023-03-24T21:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Client Script UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516587#M980420</link>
      <description>&lt;P&gt;Thanks Punit !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help ow to declare urlParm function as I am getting below error while running the example you have mentioned:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RashimWalia_0-1679698039082.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/250001i2648C3855D0DF95E/image-size/medium?v=v2&amp;amp;px=400" alt="RashimWalia_0-1679698039082.png" title="RashimWalia_0-1679698039082.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 22:47:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516587#M980420</guid>
      <dc:creator>Rashim Walia</dc:creator>
      <dc:date>2023-03-24T22:47:29Z</dc:date>
    </item>
  </channel>
</rss>

