Amit Gujarathi
Giga Sage
Giga Sage

Hi There,

I hope you're doing great.

With the participation in the ServiceNow Javascripting Challenge led by @Gagan Jolly, I m learning a lot. I thought I should share my learning on the Now community also

 

Day 1: ServiceNow Java scripting Challange

 

Statement of Work :

Write a code using the following methods 

  1. decoration
  2. add error message
  3. add or message
  4. adding message
  5. adoption

 

Solution : 

Let's first try to understand what ServiceNow GlideForm API means 

GlideForm : 

  • The GlideForm API provides methods to customize forms.
  • Works on the client side only

Lets  look into diffrent GlideForm Methods :

  1. addDecoration
    • Adds an icon on a field’s label.
    • Adding the same item twice is prevented
    • not supported on the service catalog
    • Method Signature : addDecoration(String fieldName, String icon, String title, String color)
    • Input parameters :
      • fieldName ==> String ==> The field name.
      • icon ==> String == > The font icon to show next to the field.
      • title ==> String ==> The text title for the icon.
      • color ==> String ==> A CSS color.
    • Returns :
      • Void
    • 1.jpeg

       2.jpeg

       

       

  2. addErrorMessage :
    • Displays the specified error message at the top of the form.
    • appears for approximately four seconds and then disappears
    • Method Signature: addErrorMessage (String message)
    • Input parameters :
      • message ==> String ==> Message to display.
    • Returns :
      • void
    • 3.jpeg
    • 4.jpeg

       

  3. addFormMessage :
    • Displays a floating form message at the top of the form detail section
    • It does not cover UI action
    • Method Signature : addFormMessage (String message, String type)
    • Input Parameters :
      • message ==> String ==> Message to display.
        type ==> String ==> The type of message.
    • Returns :
      • void
    • 7.jpeg

       8.jpeg

       

  4. addInfoMessage :
    • Add an info message at the top of the form
    • appears for 4 sec
    • Method Signature : addInfoMessage (String message)
    • Input parameters :
      • message ==> String ==> Message to display.
    • Returns :
      • void ==> Method does not return a value
    • 5.jpeg
    • 6.jpeg

       

  5. addOption :
    • Adds a choice to the end of a choice list field.
    • Method Signature: addOption(String fieldName, String choice value, String choice label, Number choice index)
    • Parameters : 
      • fieldName ==> String ==> The field name.
      • choice value ==> String ==> The value stored in the database.
      • choice label ==> String ==> The value displayed.
      • choice index ==> Number ==> Order of the choice in the list. The index is in a zero-based array.
    • Returns :
      • void
      • 9.jpeg

         

        10.jpeg

         

        11.jpeg

         

        function onLoad() {
        
        	g_form.addDecoration('caller_id','icon-star','Star Icon','color-green');
        	g_form.addErrorMessage('This is a fake user');
        	g_form.addInfoMessage('Please click save to submit the form');
        
        	g_form.addFormMessage('This is an info message','info');
        	g_form.addFormMessage('This is an error message','error');
        	g_form.addFormMessage('This is an warning message','warning');
        	g_form.addOption('contact_type','youtube','Youtube',3);
        }

 

Please be sure to bookmark this article and mark it as Helpful if you thought it helpful.

 

Regards,

Amit Gujarathi

Technomonk Youtube 

Amit Gujarathi Linkedin 

TheTechnomonk.com 

ServiceNow Community Amit Gujarathi 

 

 

Version history
Last update:
‎11-18-2022 06:17 AM
Updated by:
Contributors