Warning on additional comments

priisholm
Mega Expert

Hi 🙂

I want to warn itil-users every time they attempt to write in the "Additional Comments" field/box (on the incident-form) - that any comment here will go directly to the enduser (or portal).

I made an onChange:

warning.png

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  if (isLoading || newValue == '') {

  return;

  }

  if (oldValue == newValue)

  return;

  g_form.hideFieldMsg('comments', true);

  g_form.getControl('comments').focus();

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

  g_form.showFieldMsg('comments','REMEMBER, that all you write here will go directly to the enduser! ','error');

  }

}

----

It will look like this when I start writing in the "comments"-field:

comments.png

And when I remove the text from the "comments"-field it will look normal..:

comment2.png

But! My problem is that the "Additional Comments" field doesn't stay focused on the screen or the form move down, so I no longer can see the "additional comments" field... This is a problem when the "related search result" is opened... But it will also be a problem when there are too many field in the top of the form...

It seem that the form always show from the "top"..

It there a way to avoid this? (in the script or....)

screenmove.png

Thanks!

Soren

7 REPLIES 7

nayanawadhiya1
Kilo Sage

Hey Soren,



You can use alert() as well for warning.


Hi Nayan



In my case an Alert() will in show a pop-up everytime I add one letter to the "additional comments".



BR


Søren


Mike Allen
Mega Sage

Some ideas:



One, you can make that field always visible with a global user preference.


find_real_file.png



You can make the border red:


g_tabs2Sections.setActive(0); // should be the notes tab, but you can find which number is assigned in the form section table


document.getElementById('problem.comments').style.border = "solid 1px red";


But, do it without DOM manipulation, probably jQuery.



What this does for us is shift over to the tab in question and highlight the field in red.



You can hide the search context if the form is not new by setting it up like so:



find_real_file.png



CI is a mandatory field for all incidents.   If it is empty, the record is new.


And I would ALWAYS do this:



AlertNow - Share - JavaScript Alert Replacement



It replaces the hideous javascript browser alert with something with more style.   You can find it on Share:


ServiceNow Share