How to make a mandatory field non-mandatory on click

Angshuman3
Mega Guru

Hi All,

We have requirement, which says something like this :-

There is a Revert To New button, which when clicked the change should move to New state. Now this functionality is working perfect, but there is a mandatory field Conflict Justification, which needs to be skipped when some one clicks on this button. and as soon as an user clicks the button, a pop up message should be visible which would ask the user if he wants to move to New which when clicked as Yes then the action should take place.

I am trying to use the Client Callable checkbox, but isn't working. Can some one help me with it. Below I am providing the UI Action code which is working for Revert To New button :-

revertToNew(current);
action.setRedirectURL(current);

function revertToNew(changeRequestGr) {
var changeRequest = new ChangeRequest(changeRequestGr);
if (!changeRequest.revertToNew())
gs.addErrorMessage(gs.getMessage('State Model for {0} changes does not allow reverting change from {1} state', [changeRequest.getValue('type'), changeRequest.getDisplayValue('state')]));
}

 

Thanks and Regards,
Angshuman

1 ACCEPTED SOLUTION

Hey palmen,

Thanks for giving me the hint...

function goToNew(){
g_form.setMandatory('u_conflict_justification', false);

gsftSubmit(null, g_form.getFormElement(), 'revert_to_new');
}

This code snippet did the work, that I was looking for... 🙂

Thanks,
Angshuman

View solution in original post

3 REPLIES 3

Omkar Mone
Mega Sage

Hi 

If you want to use ServerSide Api's in UI Action (Client Callable ticked) you need to use gsftSubmit() funtion and after that you need to write the server code.

 

gsftSubmit(null, g_form.getFormElement(), "ui action id") triggers the UI Action which is specified in the 3rd parameter, which is the action name/element id.

It is mostly used in UI actions that have a client side and a server side script.

 

At the end of the client side script, you call gsftSubmit in order to trigger the UI Action again - this time running only the server side code.

Please also have a look at Mark Stanger's explanation:

http://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

 

Mark Correct if it helped.

 

Warm Regards,

Omkar Mone

www.dxsherpa.com

palmen
Tera Guru

Something like this should probably work

find_real_file.png

// Client side onclick function
function goToNew(){
   g_form.setMandatory('u_conflict_justification', false);

   // Call the UI Action and skip the 'onclick' function
   gsftSubmit(null, g_form.getFormElement(), 'revert_to_new'); // MUST call the 'Action name' set in this UI Action
}

// Code that runs without 'onclick'
// Ensure call to server side function with no browser errors
if (typeof window == 'undefined')
   yourScript();

function yourScript() {
   // Set Incident state to active, update and reload the record
   current.state = 'VALUE OF NEW STATE';
   action.setRedirectURL(current);
}

 

Hey palmen,

Thanks for giving me the hint...

function goToNew(){
g_form.setMandatory('u_conflict_justification', false);

gsftSubmit(null, g_form.getFormElement(), 'revert_to_new');
}

This code snippet did the work, that I was looking for... 🙂

Thanks,
Angshuman