onChange client script - make comments mandatory upon modification of state

mitzaka
Mega Guru

Hi SNC,

 

I am trying to set up a use case where when a user tries to close a catalog task, he has to enter customer comment notes.

For the action of closing the catalog task I have an UI Action button on the catalog task form, which has the following code:

 

        current.task_state = 3;

        current.update();

 

For the user comments field I am using the customer comments field from the RITM.

And for the script I wrote, it's on the catalog task table, and it looks like this:


find_real_file.png

 

So at first sight it all seems OK, but if I change the state from the drop down list. However, when I try to click the UI button, it does not work. It just closes the task without prompting me for anything.

 

Any ideas where am I going wrong?

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Add this code to your ui action



if(g_form.getValue('comments') == ''){


                //Remove any existing field message, set comments mandatory, and show a new field message


                try{g_form.hideFieldMsg('comments');}catch(e){}


                g_form.setMandatory('comments', true);


                g_form.showFieldMsg('comments','Comments are mandatory','error');


                return false;   //Abort submission


          }




Use the ui action that has both client anbd server side code. this will be client side code,   and


current.task_state = 3;


        current.update();


this will be your server side code.


-Anurag

View solution in original post

8 REPLIES 8

sushant007
Kilo Guru

UI action button will directly update record and wont give chance to your onChange script to alert/make field mandatory.


If this is the case you could set this mandatory in the ui action script rather than the on change script.


I am looking for the alternative.


But even at the end of UI action if you write current.update(); this wont be checking for mandatory fields are filled or not!




Daryll Conway
Giga Guru

I think you need to use 'producer.comments' instead of 'request_item.comments' or it might be 'producer.request_item.comments' I'm not sure with out access to your form.


Whenever you use GSC variables you need to prefix producer to the field you are trying to use.