TMACUL

http://www.servicedeskusers.com/Changing_Error_Alert_Color_and_adding_Error_Alert_Pop-ups

Blog Post created by TMACUL Champion on Jan 1, 2016

Changing Error Alert Color and adding Error Alert Pop-ups

 

From SDU

Jump to: navigation, search

 

To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.


 

Overview

Our analysts complained that they were loosing tickets because USD displayed error messages in the same color, yellow, as successful save messages. The analysts would miss the error message and the click “Close Window” button thinking that the ticket was created.
We had an issue open with CA, and their advice was to change BACKGROUND-COLOR for alertmsg class in styles_ahd.css. Of course, that would not do us any good, because it would apply to successful save messages as well.
I made modifications to a couple of java script functions to change this behavior. Originally I did two things: made the color of the error messages red, and in addition to that, displayed the same error message in a pop-up. In the end we decided that red was too much, since we now have the pop-up. But at least we know how to change the color, if we want to.
There are two different scenarios that lead to displaying of an alert message. If you want your color change to affect both scenarios, you will have to customize two Java script functions.

 

The 1st scenario is triggered when an unconditionally required field (i.e. defined as required at the schema level) is not filled in. The function showAlertMsg() is called in this case, and that’s the one we need to modify. This scenario is covered by Part I of this article.

 

The 2nd scenario is when either data partition constraints or SPL triggers enforce data validation. In this case, endDetail() is the function that needs to be modified. The details are provided in Part II of the article

 

Please note that this change will affect all detail forms in all interfaces in USD, not only tickets for analysts.

Part I. Alerts for unconditionally required fields

Step 1. Create sitemods.js

If you don’t have sitemods.js in $NX_ROOT\site\mods\www\wwwroot\scripts, copy it from $NX_ROOT\bopcfg\www\wwwroot\scripts.

Step 2. Add showAlertMsg() function to sitemods.js

Copy function showAlertMsg() from $NX_ROOT\bopcfg\www\wwwroot\scripts\detail_form.js and paste it into $NX_ROOT\site\mods\www\wwwroot\scripts\sitemods.js
Note: Any patches/updates to showAlertMsg() in $NX_ROOT\bopcfg\www\wwwroot\scripts\detail_form.js must be manually ported to showAlertMsg() in $NX_ROOT\site\mods\www\wwwroot\scripts\sitemods.js

Step 3. Modify showAlertMsg() in sitemods.js

If you want to change the color of the error messages, add this line:

alertmsg.style.backgroundColor="red";

If you want error messages to be displayed in a pop-up, remove the condition that prevents pop-up for Analyst Interface.
Original code:

if ((ahdtop.cstUsingScreenReader||ahdtop.cfgUserType!="analyst")&&(typeof popup_alertmsg!="boolean"||popup_alertmsg))

Modified code:

if (typeof popup_alertmsg!="boolean"||popup_alertmsg)

Step 4. Clear your Web browser cache

Clear your Web browser cache to test (no need to recycle USD)

Example Modified showAlertMsg()

function showAlertMsg(msg,popup_alertmsg)

{

  e=document.getElementById("alertmsgText");

  if(e!=null&&typeof msg=="string"&&msg.length>0)

  {

   if(typeof AlertMsg!="string")

  AlertMsg="";

   if(AlertMsg.length>0)

  AlertMsg+="<BR>"+msg;

   else

  AlertMsg=msg;

   if(e.innerHTML!=AlertMsg)

   {

  e.innerHTML=AlertMsg;

   // Commented out the original condition that prevents popups for analyst interface, and replaced it with a simplified one.

   //if ((ahdtop.cstUsingScreenReader||ahdtop.cfgUserType!="analyst")&&(typeof popup_alertmsg!="boolean"||popup_alertmsg))

   if (typeof popup_alertmsg!="boolean"||popup_alertmsg) 

   {

   var popupMsg=AlertMsg.replace(RegExp("<BR>","gi"),"\\n")

  .replace(RegExp('\n',"g"),"\\n")

  .replace(RegExp('"',"g"),'\\"');

  window.setTimeout('alert("'+popupMsg+'")',5);

   }

   }

   var alertmsg=document.getElementById("alertmsg");

   if(alertmsg!=null&&alertmsg.style.display!="block")

   {

  alertmsg.style.display="block";

   // Change color for the message within the page, in addition to the popup

  alertmsg.style.backgroundColor="red";

  adjScrollDivHeight();

   }

  }

}

Part II. Alerts for data constraint and spell trigger validations

Step 1. Add endDetail() function to sitemods.js

Copy function endDetail() from $NX_ROOT\bopcfg\www\wwwroot\scripts\detail_form.js and paste it into $NX_ROOT\site\mods\www\wwwroot\scripts\sitemods.js
Note: Any patches/updates to endDetail() in $NX_ROOT\bopcfg\www\wwwroot\scripts\detail_form.js must be manually ported to endDetail() in $NX_ROOT\site\mods\www\wwwroot\scripts\sitemods.js

Step 2. Modify endDetail() in sitemods.js

If you want to change the color of the error messages, find line

e.style.display="block";

and add the following under it:

if (AlertMsg.substr(0,15) != "Save Successful") e.style.backgroundColor="red";

If you want error messages to be displayed in a pop-up, find line

if(typeof e=="object"&&e!=null){

and add the following code under it:

if (AlertMsg.substr(0,15) != "Save Successful")  // prevent popup for success messages 

   {

   var popupMsg=AlertMsg.replace(RegExp("<BR>","gi"),"\\n")

  .replace(RegExp('\n',"g"),"\\n")

  .replace(RegExp('"',"g"),'\\"');

  window.setTimeout('alert("'+popupMsg+'")',3);

   }

Step 3. Clear your Web browser cache

Clear your Web browser cache to test (no need to recycle USD)

Example Modified endDetail()

function endDetail()

{

  detailEndRow();

  var out="";

  if(_dtl.tableStarted)

  out="</TABLE>\n";

  if(_dtl.formStarted)

  out+="</FORM>";

  docWriteln(out);

  _dtl.tableStarted=false;

  if(typeof AlertMsg=="string"&&AlertMsg.length>0)

  {

   var e=document.getElementById("alertmsgText");

   if(typeof e=="object"&&e!=null){

   // Popup alert with same text that is displayed in alertmsg area of the form

   if (AlertMsg.substr(0,15) != "Save Successful")  

   {

   var popupMsg=AlertMsg.replace(RegExp("<BR>","gi"),"\\n")

  .replace(RegExp('\n',"g"),"\\n")

  .replace(RegExp('"',"g"),'\\"');

  window.setTimeout('alert("'+popupMsg+'")',3);

   }

 

  e.innerHTML=AlertMsg;

  e=document.getElementById("alertmsg");

  e.style.display="block";

   // display alert in red

   if (AlertMsg.substr(0,15) != "Save Successful")

  e.style.backgroundColor="red";

  adjScrollDivHeight();

   }

  }

  if(typeof _dtl.firstField=="string")

  {

  _dtl.firstField=document.getElementById(_dtl.firstField);

   if(_dtl.firstField!=null)

   {

  _dtl.onload=window.onload;

  window.onload=detailOnload;

   }

   else if(_dtl.edit)

  _dtl.form[0].style.display="block";

  }

  if(_dtl.center)

  docWriteln("</CENTER>");

  if(typeof ahdtop=="object"&&typeof ahdtop.detailForms=="object"

  &&(typeof alg_factory!="string"||alg_factory==propFactory))

  {

   if(typeof argPersistentID=="string"&&argPersistentID.length>0)

  ahdtop.detailForms[argPersistentID]=window.parent;

   if(propFactory=="chg"&&typeof argChgRefNum=="string")

  ahdtop.detailForms["chg"+argChgRefNum]=window.parent;

   else if((propFactory=="cr"||propFactory=="iss")&&typeof argRefNum=="string")

  ahdtop.detailForms[propFactory+argRefNum]=window.parent;

  }

  if(_dtl.spellchk)

  {

  do_hiddenfm('spell_form','main_form');

  }

} // endDetail()

Retrieved from "http://www.servicedeskusers.com/Changing_Error_Alert_Color_and_adding_Error_Alert_Pop-ups"

Outcomes