How to reload a form from a on change client script ?

sumeetkumardas
Kilo Contributor

I tried with this script but it doesn't works .

if (( oldValue == -5   && newValue == 1 ) || ( oldValue == -5 && newValue == 2 ) || ( oldValue == -5   && newValue == 7 ) || (oldValue == -5   && newValue == 4) || (oldValue == -5 && newValue == 5))

  {

  return confirm('Incident in Pending state can only move to In Progress or Resolved');

  reloadWindow(incident);

  location.reload();

  var answer = confirm("Incident in Pending state can only move to In Progress or Resolved");

  alert('success1'+answer);

  if (answer == ok)

  {

  alert('success');

  reloadWindow(window);

  }

  else

  reloadWindow(window);

  }

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron
10 REPLIES 10

That actually deviates the requirement :-


Create a onChange client script at EGP level for Incident which will run on Incident state field. If the oldvalue is Pending and newvalue in the script is other than In progress or Resolved than display a message that Incident in Pending state can only move to In Progress or Resolved. And then rollback the incident state.


This sounds like a very easy job for a before business rule (check your state values against mine to be sure.)



Condition: previous.state == -5 && (current.state != 2 || current.state != 6)



Script:


gs.addErrorMessage('Pending incidents can only move to In Progress or Resolved.');



Ideally, you should use the g_form.addOption() g_form.removeOption() to prevent the user from choosing the wrong option, or make the state field read-only and use UI actions (buttons) to drive the state.


The first line inside your condition is a return statement.   Once the code hits the line:



return confirm('Incident in Pending state can only move to In Progress or Resolved');



it will get out of your onChange script completely and ignore the rest of the code in your function.   If you change that to:



alert('Incident in Pending state can only move to In Progress or Resolved');



it should just pop up an alert and then do the rest of your code.  



That being said, I would agree with Mike that it makes more sense to remove the options you don't want available so the user can't choose them in the first place and with Chuck that this requirement would probably be better suited for a before business rule.



-Steve


I generally do not show the end user things he cannot choose at any given time.   It just invites frustration and forces a bad perception of the platform as a whole.


Thank you Mike , Stephen & Chuck for the suggestions . It really helped me a lot to get through the solution