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-23-2023 04:56 AM
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 2: ServiceNow Java scripting Challange
Statement of Work :
Write a code using the following methods
- clearAllFormMessages
- clearMessages
- clearOptions
- clearValue
- disableAttachments
- enableAttachments
- flash
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 :
- clearAllFormMessages
- Removes all form messages of any type.
- Method Signature : clearAllFormMessages()
- Input parameters :
- None
- Returns :
- Void
- clearMessages:
- Removes all informational and error messages from the top of the form.
- Method Signature: clearMessages()
- Input parameters :
- None
- Returns :
- void
- clearOptions :
- Removes all options from the choice list.
- Method Signature : clearOptions(String fieldName)
- Input Parameters :
- fieldName ==> String ==> Name of the field.
- Returns :
- void
- clearValue:
- Removes any value(s) from the field.
- Method Signature : clearValue(String fieldName)
- Input parameters :
- fieldName ==> String ==> Name of the field.
- Returns :
- void ==> Method does not return a value
- disableAttachments:
- Prevents file attachments from being added.
- Method not available for mobile
- Method Signature: disableAttachments()
- Parameters :
- fieldName ==> String ==> The field name.
- choiceValue ==> String ==> The value stored in the database.
- choiceLabel ==> String ==> The value displayed.
- choiceIndex ==> Number ==> Order of the choice in the list. The index is into a zero based array.
- Returns :
- void
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.clearMessages();
g_form.clearOptions('contact_type');
//g_form.clearValue('description');
if (g_form.getValue('category') == 'software') {
g_form.disableAttachments();
g_form.flash('caller_id','#FFFACD',0);
}
else {
g_form.enableAttachments();
}
}
Please be sure to bookmark this article and mark it as Helpful if you thought it helpful.
Regards,
Amit Gujarathi
Labels: