Amit Gujarathi
Giga Sage
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 03-01-2023 07:43 PM
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
- decoration
- add error message
- add or message
- adding message
- 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 :
- 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
- 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
- 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.
- message ==> String ==> Message to display.
- Returns :
- void
- 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
- 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
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
ServiceNow Community Amit Gujarathi
Labels:
- 699 Views