- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-12-2019 10:52 AM
Field-Based APIs
Hide/Display variable : g_form.setDisplay(<fld>,true/false);
Disable a field : g_form.setDisable(<fld>,true/false);
Field ReadOnly : g_form.setReadOnly(<fld>,true/false);
Clear Value from Field : g_form.clearValue(<fld>);
Change Label of Field : g_form.setLabelOf(<fld>,newlabel);
Make field mandatory : g_form.setMandatory(<fld>,true/false);
Set Value of Field : g_form.setValue(<fld>,value);
Show error and scroll : g_form.showErrorBox(<fld>,msg,true/false);
to field
Add Options to Choice : g_form.addOption(<fld>,value,label,index);
filed
Remove Options from : g_form.removeOption(<fld>,value);
Choice field
Clear all Options from : g_form.clearOptions(<fld>);
Choice Field
Get Reference field : g_form.getReference(<fld>,callbackfunction);
Value and Attributes
Flash a particular field : g_form.flash(table.name,color,no of flashes)
Get Integer Value of Field: g_form.getIntValue(<fieldname>);
Get Decimal Value of Field: g_form.getDecimalValue(<fieldname>);
**Note:
<fld> Represent the field name on which the function has to work
value - is something what you have to set.
true/false - true is for enabling, false is for disable.
Related List APIs
Show Related List* : g_form.showRelatedList(<relatedlisttablename>);
Hide Related List : g_form.hideRelatedList(<relatedlisttablename>);
Show All Related Lists : g_form.showRelatedLists();
Hide All Related Lists : g_form.hideRelatedLists();
Sections based API
Show/Hide a Section : g_form.setSectionDisplay(<sectionname>,true/false);
Get All Sections* : g_form.getSectionNames();
Get All Sections** : g_form.getSections();
Check whether section : g_form.isSectionVisible(<sectionname>);
is Visible
Note:
*Returns all the sections including the invisible ones,
**Not available on Mobile Platform
<sectionname>: the section name in ServiceNow is created by
replacing the 1st space by "_" and trimming rest of the spaces,
for ex: if a section on the form is created as "Section Specific API"
then section name is "section_specificapi".
Decorations API
Add decorations(not applicable : g_form.addDecoration(<fld>,iconname,titleforicon);
for Catalog Client Scripts)
Remove Decorations(not applicable : g_form.removeDecoration(<fld>,iconname,titleforicon);
for Catalog Client Scripts)
LiveUpdate running on form* : g_form.isLiveUpdating()
Note:
*Live update can detect any change of the data on the form from another session.
HTML based APIs
Control a Field : g_form.getControl(<fldname>);
Get an HTML Element from Parameter* : g_form.getElement(<parameter>);
Get HTML element of Option** : g_form.getOption(<fieldname>,value);
Get HTML element of Form : g_form.getFormElement();
Get HTML element of HelpText : g_form.getHelpTextControl(<fldname>);
Note:
*Not available in the Mobile and Service Portal
**The method will not work on read-only fields, and if the field is not present on the form it will result in null.
Action Specific API
Submit a form : g_form.submit(actionName);
Save a form : g_form.save();
Best Practices Client Scripting
Use UI policies instead of Client scripts: For basics like making a field read-only, mandatory best practice suggests to use UI Policies.
Always use isLoading check when in onChange Client Scripts: All the onChange client script will get executed onLoad as well,
always check whether the form is loading by isLoading function.
Avoid Using GlideRecord function in Client script: Replace the calls by GlideAjax.
Avoid DOM(manipulation of form elements): As all the elements might be changed in the future release,
and to avoid complications avoid doing DOM.
Use g_scratchpad to minimize server calls: When working with a lot of data write a Display Business Rule and make the data available to Client Side.
When using JQuery in Client Scripts: Instance before London, has no possibility of isolating a JQuery Script,
but instances in London and above has a strict client mode, where methods like window, eval would only work if isolation is turned on.
- 4,264 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Nice work. For the "Note" section in the Field Based APIs, you have the same verbiage twice. Also in that same section clearOptions has a space after . Just throwing that out there.
Overall, good job!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very helpful work,Good job phanindra.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very very helpful Phani. Keep it up.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
That was an "Everything at one place" kind of article. So helpful. Keep writing more!!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
All in one kind of thing.....
Thanks Phani keep writing........
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
That was an "Everything at one place" kind of article. So helpful. Keep writing more!!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Nice Article!
Good Work
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Awesome. Glad you found my reply Helpful.
Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Sure, Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Kiran
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
It's really helpful .Thank you for sharing !!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Good one!! Keep sharing the knowledge !!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very nice article. Good Job, Really helpful..!!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I like your list of helpful functions........ how would you approach changing a field value (price) to be a negative number? For example: enter a price and save record.......when it saves, it converts the Positive Price to be a Negative price field? I've tried simple approaches like x = "field", and y = x * -1
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @psphanindrakuma ,
This article helps a lot. Appreciate our effort for this. Thank you very much
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Can you provide the same for server side API's
