Unable to save field value using a script in UI Action

Community Alums
Not applicable

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.

This is what I have for the UI Action:

Name: Open Data Call

Action: open_data_call

Order: 100

Form Button:

Show Update: Checked

Client: Checked

 

Onclick: updateState()

Condition: current.state=='open_data_call'

 

Script:

function updateState() {

     g_form.setValue('state', 'Pending Approval'); //Should 'Pending Approval' be the value?

     gsftSubmit(null, g_formElement()),  'open_data_call';

}

Not sure why it isn't saving on the form. I can see the update in the state field.

 

1 ACCEPTED SOLUTION

ChuckAtTyler
Mega Expert

Hey Shannon,

 

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.

A screenshot would help but I would try the following:

  • Uncheck "Client"
  • Change Script to below:

 

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
}

 

If you had a screenshot of the record itself that could help, but above might get you pointed in the right direction.

 

Thanks,

Charles

View solution in original post

9 REPLIES 9

Please share a screenshot of the UI action.

 

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.

 

https:// <your instance URL> /sys_choice_list.do?sysparm_query=label%3Dpending%20approval%5Eelement%3Dstate%5Ename%3Dsys_user_has_role&sysparm_view=

 

It might be a number or a backend value like "pending_approval" but please check, set that, and then try.

Community Alums
Not applicable

Here is what I have. I will check the link but I did verify from the table what the element values are.

Community Alums
Not applicable
 

The nesting is not right. As this can now be achieved just using server side code, please do the following.

 

a. Uncheck Client checkbox

 

b. Remove existing code from UI action script area

 

c. Paste the code below

 

if(typeof window == 'undefined')
saveState();

function saveState(){
current.setValue("state",  "pending_approval");
current.update();

 

action.setRedirectURL(current);
}

Ihor Kochetkov
Tera Contributor

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.