Make field mandatory only by clicking a ui action button

Alessia Russo
Tera Expert

Hi everybody! I would like to make a field in my form mandatory only if a user of a group is trying to click a specific ui action button. How could I do it? With some script? Which one?

I've tried with policy and br, but it make the field mandatory for all the other ui buttons in the form in that particular state.

Thanxs

5 REPLIES 5

Shashank_18
Mega Guru

In the UI Action, put current.setMandatory(Field Name, true);

Hope this will resolve your issue.

when I put it in the ui action it doesn't work, when I click that button I have a script on that works, so maybe I've to put it first of the script running?

I've to make the field mandatory before this script run, so how could I put it in the ui action? Here the script in my ui action button:

Inkedexscript.jpg

DrewW
Mega Sage
Mega Sage

Sounds like the button needs to run a client script and it needs to do

g_form.setMandatory();

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/client/c_GlideFormAPI#r_GlideFormSe...

 

If you still need to run part of the client script for the button on the server side then you can do something like this

function CLIENTFUNCTION() {
    //Put Client Code Here
    gsftSubmit(null, g_form.getFormElement(), 'UI_ACTION_NAME');
}

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

function serverSideCodeToRun() {
    //Put Server side code hear.
}

 

Nitish Saini
Tera Expert

Hi @Alessia Russo 

Follow these steps to make field mandatory on click of UI Action :-

 

UI Action settings

  • Client: Checked (so it can run on the client side)

  • Action name: mark_mandatory

  • Form button: Checked

  • In the Script section :- Just use this line of code inside the function 
    g_form.setMandatory('field_name', true);   // Write your original field name in replace of field_name

    Please accept my answer and mark as helpful/correct if it resolves your query.

     

    Regards, 
    Nitish