<?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 Unable to save field value using a script in UI Action in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518284#M981062</link>
    <description>&lt;P&gt;I am working on a UI action that when clicked, changes the state field to pending approval. I can see the field value update when I click the UI Action however it doesn't save the value.&lt;/P&gt;&lt;P&gt;This is what I have for the UI Action:&lt;/P&gt;&lt;P&gt;Name: Open Data Call&lt;/P&gt;&lt;P&gt;Action: open_data_call&lt;/P&gt;&lt;P&gt;Order: 100&lt;/P&gt;&lt;P&gt;Form Button:&lt;/P&gt;&lt;P&gt;Show Update: Checked&lt;/P&gt;&lt;P&gt;Client: Checked&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onclick: updateState()&lt;/P&gt;&lt;P&gt;Condition: current.state=='open_data_call'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Script:&lt;/P&gt;&lt;P&gt;function updateState() {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;g_form.setValue('state', 'Pending Approval'); //Should 'Pending Approval' be the value?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;gsftSubmit(null, g_formElement()),&amp;nbsp; 'open_data_call';&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Not sure why it isn't saving on the form. I can see the update in the state field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Mar 2023 22:41:15 GMT</pubDate>
    <dc:creator>Community Alums</dc:creator>
    <dc:date>2023-03-27T22:41:15Z</dc:date>
    <item>
      <title>Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518284#M981062</link>
      <description>&lt;P&gt;I am working on a UI action that when clicked, changes the state field to pending approval. I can see the field value update when I click the UI Action however it doesn't save the value.&lt;/P&gt;&lt;P&gt;This is what I have for the UI Action:&lt;/P&gt;&lt;P&gt;Name: Open Data Call&lt;/P&gt;&lt;P&gt;Action: open_data_call&lt;/P&gt;&lt;P&gt;Order: 100&lt;/P&gt;&lt;P&gt;Form Button:&lt;/P&gt;&lt;P&gt;Show Update: Checked&lt;/P&gt;&lt;P&gt;Client: Checked&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onclick: updateState()&lt;/P&gt;&lt;P&gt;Condition: current.state=='open_data_call'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Script:&lt;/P&gt;&lt;P&gt;function updateState() {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;g_form.setValue('state', 'Pending Approval'); //Should 'Pending Approval' be the value?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;gsftSubmit(null, g_formElement()),&amp;nbsp; 'open_data_call';&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Not sure why it isn't saving on the form. I can see the update in the state field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 22:41:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518284#M981062</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2023-03-27T22:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518293#M981065</link>
      <description>&lt;P&gt;Hey Shannon,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any reason this has to be a client UI Action? Essentially this means that the changes you make are within the browser and not the server. So while the changes may happen as soon as you select the UI Action, this doesn't mean that the record value has actually had the value changed.&lt;/P&gt;&lt;P&gt;A screenshot would help but I would try the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Uncheck "Client"&lt;/LI&gt;&lt;LI&gt;Change Script to below:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function updateState() {
     current.state = 'Pending Approval'); // This depends on the backend of value of the options for the 'state' field
     current.update(); // This updates the current record
     action.setRedirectURL(current); // Redirects the user to the current record after saving, Not necessary, but recommended
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you had a screenshot of the record itself that could help, but above might get you pointed in the right direction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Charles&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 22:51:50 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518293#M981065</guid>
      <dc:creator>ChuckAtTyler</dc:creator>
      <dc:date>2023-03-27T22:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518301#M981068</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Line&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;gsftSubmit(null, g_formElement()&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;,&amp;nbsp; 'open_data_call';&lt;/EM&gt; should be changed to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;gsftSubmit(null, g_formElement(),&amp;nbsp; 'open_data_call'&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please try adding the code below to your UI action.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;typeof&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;window&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;==&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;'undefined'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;saveState&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;function&lt;/SPAN&gt;&lt;SPAN&gt; saveState&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;current.setValue("state",&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;"Pending Approval")&lt;/SPAN&gt;&lt;SPAN&gt;; // Ensure this is the backend value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;current.&lt;/SPAN&gt;&lt;SPAN&gt;update&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;action.&lt;/SPAN&gt;&lt;SPAN&gt;setRedirectURL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;current&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Arav&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 23:11:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518301#M981068</guid>
      <dc:creator>Arav</dc:creator>
      <dc:date>2023-03-27T23:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518310#M981071</link>
      <description>&lt;P&gt;&lt;EM&gt;I am getting the same behavior with the script update. It isn't saving the update to the record. It does show the update in the state field right before it exits out but when I get to the list view the value is changed back to the previous state.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 23:57:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518310#M981071</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2023-03-27T23:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518322#M981074</link>
      <description>&lt;P&gt;Please share a screenshot of the UI action.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, using the URL below, change the table from "sys_user_has_role" to your table name and check what is present in column "Value". That is the value to be set for state.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;https:// &amp;lt;your instance URL&amp;gt; /sys_choice_list.do?sysparm_query=label%3Dpending%20approval%5Eelement%3Dstate%5Ename%3Dsys_user_has_role&amp;amp;sysparm_view=&lt;/P&gt;
&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;It might be a number or a backend value like "pending_approval" but please check, set that, and then try.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 00:25:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518322#M981074</guid>
      <dc:creator>Arav</dc:creator>
      <dc:date>2023-03-28T00:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518327#M981076</link>
      <description>&lt;P&gt;Here is what I have. I will check the link but I did verify from the table what the element values are.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 00:43:45 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518327#M981076</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2023-03-28T00:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518328#M981077</link>
      <description />
      <pubDate>Tue, 28 Mar 2023 00:52:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518328#M981077</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2023-03-28T00:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518334#M981080</link>
      <description>&lt;P&gt;The nesting is not right. As this can now be achieved just using server side code, please do the following.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a. Uncheck Client checkbox&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;b. Remove existing code from UI action script area&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;c. Paste the code below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;typeof&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;window&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;==&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;'undefined'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;saveState&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;function&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;saveState&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;current.setValue("state",&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;"pending_approval")&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;current.&lt;/SPAN&gt;&lt;SPAN&gt;update&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;action.&lt;/SPAN&gt;&lt;SPAN&gt;setRedirectURL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;current&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 01:26:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2518334#M981080</guid>
      <dc:creator>Arav</dc:creator>
      <dc:date>2023-03-28T01:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2519510#M981539</link>
      <description>&lt;P&gt;This was what I needed and it is now working as expected! Onward to more scripting! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 17:58:53 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2519510#M981539</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2023-03-28T17:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save field value using a script in UI Action</title>
      <link>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2734313#M1054680</link>
      <description>&lt;P&gt;I had the same and resolved it with adding Write ACL on field State (which I'm changing in my client script) which allows to change the state for end user who clicks this button. So first make sure that this user can change the status manually on the form, if no - it's ACL issue and button will not work until you fix ACL.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 08:45:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/unable-to-save-field-value-using-a-script-in-ui-action/m-p/2734313#M1054680</guid>
      <dc:creator>Ihor Kochetkov</dc:creator>
      <dc:date>2023-11-16T08:45:07Z</dc:date>
    </item>
  </channel>
</rss>

