<?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 MRVS  Onsubmit Trim spaces in ServiceNow Studio forum</title>
    <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348888#M3500</link>
    <description>&lt;P&gt;Hi All ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have catalog item i am using varible set under it i have multi row variable set in that i have one field called test which is a single line text . before submitting form if i have any spaces before it should clear . how do i do .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  var str = g_form.getValue('variable_1');
        var wsr = str.trim();
        g_form.setValue('variable_1',wsr );
    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the one i used&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Aug 2025 16:42:04 GMT</pubDate>
    <dc:creator>Rajeevreddy</dc:creator>
    <dc:date>2025-08-11T16:42:04Z</dc:date>
    <item>
      <title>MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348888#M3500</link>
      <description>&lt;P&gt;Hi All ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have catalog item i am using varible set under it i have multi row variable set in that i have one field called test which is a single line text . before submitting form if i have any spaces before it should clear . how do i do .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  var str = g_form.getValue('variable_1');
        var wsr = str.trim();
        g_form.setValue('variable_1',wsr );
    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the one i used&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 16:42:04 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348888#M3500</guid>
      <dc:creator>Rajeevreddy</dc:creator>
      <dc:date>2025-08-11T16:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348901#M3501</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/35943"&gt;@Rajeevreddy&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You won't be able set like that, it is not simple getting the values from MVRS and setting.&lt;/P&gt;&lt;P&gt;MVRS&amp;nbsp; values are accessed as a JSON string. like a array.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onSubmit() {

  var raw = g_form.getValue(mrvsName);
  if (!raw) return true;

  var rows = JSON.parse(raw); // MRVS returns JSON array of row objects
  var changed = false;

  for (var i = 0; i &amp;lt; rows.length; i++) {
    if (rows[i].hasOwnProperty('test')) {
      var v = rows[i]['test'];
      if (typeof v === 'string') {
        var trimmed = v.trim(); // removes leading/trailing spaces
        if (trimmed !== v) {
          rows[i]['test'] = trimmed;
          changed = true;
        }
      }
    }
  }

  if (changed) {
    g_form.setValue(mrvsName, JSON.stringify(rows));
  }
  return true;
}
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use above code to trim the "test" field in MVRS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;&lt;STRONG&gt;Bhimashankar H&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;-------------------------------------------------------------------------------------------------&lt;BR /&gt;If my response points you in the right directions, please consider marking it as 'Helpful' &amp;amp; 'Correct'. Thanks!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 17:03:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348901#M3501</guid>
      <dc:creator>Bhimashankar H</dc:creator>
      <dc:date>2025-08-11T17:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348907#M3502</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/35943"&gt;@Rajeevreddy&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Did you create the client script in the MVRS (variable set)?&lt;/P&gt;&lt;P&gt;if not create the client script in the MVRS as you are saying the variable you want to trim spaces against is in the mvrs&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChaitanyaILCR_1-1754931902379.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/462200i5A1C7F87DA81E4C0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChaitanyaILCR_1-1754931902379.png" alt="ChaitanyaILCR_1-1754931902379.png" /&gt;&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;function onSubmit() {
    g_form.setValue('variable_1', g_form.getValue('variable_1').trim());
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Please mark my answer as&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;helpful/correct&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/STRONG&gt;if it resolves your query.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;Regards,&lt;BR /&gt;Chaitanya&lt;/I&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 17:05:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348907#M3502</guid>
      <dc:creator>Chaitanya ILCR</dc:creator>
      <dc:date>2025-08-11T17:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348954#M3503</link>
      <description>&lt;P&gt;Its not working chaitanya . It works only on portal if i submit from classis view its not working&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 17:51:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348954#M3503</guid>
      <dc:creator>Rajeevreddy</dc:creator>
      <dc:date>2025-08-11T17:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348957#M3504</link>
      <description>&lt;P&gt;Hi Bhima , Its not working&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 17:52:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3348957#M3504</guid>
      <dc:creator>Rajeevreddy</dc:creator>
      <dc:date>2025-08-11T17:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3349033#M3505</link>
      <description>&lt;P&gt;Hey &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/35943"&gt;@Rajeevreddy&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is working code; I made simple for you.&amp;nbsp; Try it out.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onSubmit() {

  var raw = g_form.getValue(mrvsName);
  if (!raw) return true;

  var rows = JSON.parse(raw); // MRVS returns JSON array of row objects

  for (var i = 0; i &amp;lt; rows.length; i++) {
      var v = rows[i]['test'];
        var trimmed = v.trim(); // removes leading/trailing spaces
          rows[i]['test'] = trimmed;
  }

    g_form.setValue(mrvsName, JSON.stringify(rows));
 
  return true;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would suggest first write above code in any other field on change script. Ensure that you first filled the MVRS then change the other field. then this code will execute. Once it is executed then again click on pencil icon on this MVRS then check if spaces are removed or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked it on my PDI, it is working.&amp;nbsp; If you observe keenly, it won't show the space when you look on form but when you open that row on MVRS then you will see if this code is removed the spaces or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;&lt;STRONG&gt;Bhimashankar H&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;-------------------------------------------------------------------------------------------------&lt;BR /&gt;If my response points you in the right directions, please consider marking it as 'Helpful' &amp;amp; 'Correct'. Thanks!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 18:59:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3349033#M3505</guid>
      <dc:creator>Bhimashankar H</dc:creator>
      <dc:date>2025-08-11T18:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3349120#M3507</link>
      <description>&lt;P&gt; Hi Bhima , Did i miss anything or i am referencing it wrongly ?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snag_7d3de0d.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/462272i4F422416BE261F71/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snag_7d3de0d.png" alt="Snag_7d3de0d.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 21:00:05 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3349120#M3507</guid>
      <dc:creator>Rajeevreddy</dc:creator>
      <dc:date>2025-08-11T21:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3349245#M3508</link>
      <description>&lt;P&gt;Try on some onChange script first&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;&lt;STRONG&gt;Bhimashankar H&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;-------------------------------------------------------------------------------------------------&lt;BR /&gt;If my response points you in the right directions, please consider marking it as 'Helpful' &amp;amp; 'Correct'. Thanks!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2025 04:07:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3349245#M3508</guid>
      <dc:creator>Bhimashankar H</dc:creator>
      <dc:date>2025-08-12T04:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3349257#M3509</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/35943"&gt;@Rajeevreddy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;why not add validation on change of that variable within MRVS?&lt;/P&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;P&gt;you can use onChange, trim the space and set the value again, but remember you are setting value again and onChange will trigger again so it should not go in loop&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2025 05:01:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3349257#M3509</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-08-12T05:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: MRVS  Onsubmit Trim spaces</title>
      <link>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3350006#M3527</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/35943"&gt;@Rajeevreddy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for marking my response as helpful.&lt;/P&gt;
&lt;P&gt;As per new community feature you can mark multiple responses as correct.&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct as well so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2025 14:18:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-studio-forum/mrvs-onsubmit-trim-spaces/m-p/3350006#M3527</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-08-12T14:18:02Z</dc:date>
    </item>
  </channel>
</rss>

