Where are new, custom GlideDBFunctions created?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2018 12:51 PM
I see an example to create a custom function and use it in a script (see https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_reference/GlideDBFunctionBuilderScoped/concept/GlideDBFunctionBuilderScopedAPI.html#ariaid-title10).
Can I define a custom function and reference it in a table's function field? If so, how?
Answer
I posted this question thinking that custom functions could be devised and referenced in the
"Function definition" field of a "Function field". I wanted to know where such functions, once
defined, could be stored. I know believe that is not possible. Rather, the GlideDBFunctionBuilder
method is for scripts to define functions for the GlideRecord "addFunction" method. Example below.
// ------------------------------ ----------- ------------------------------------------- -----------
// Example GlideDBFunctionBuilder 16-mar-2018 Initial version Version 1.0
// ------------------------------ ----------- ------------------------------------------- -----------
//
// Exercise the new GlideRecord addFunction method. Based on ServiceNow documentation
// for "dayofweek" under "GlideDBFunctionBuilder - Scoped, Global" for Kingston.
//
// Define the function.
var functionBuilder = new GlideDBFunctionBuilder();
var dayOfWeekFunction = functionBuilder.dayofweek();
dayOfWeekFunction = functionBuilder.field ( 'opened_at' );
dayOfWeekFunction = functionBuilder.constant ( '2' );
dayOfWeekFunction = functionBuilder.build();
//
// Build an array of days.
var days = [ 'Code_2', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ];
//
// Show results for ten incidents.
var gr = new GlideRecord ( 'incident' );
gr.addFunction ( dayOfWeekFunction );
gr.setLimit ( 10 );
gr.query();
while( gr.next() ) {
gs.log( gr.number + ' was opened at ' + gr.opened_at.getDisplayValue() +
', a ' + days[gr.getValue(dayOfWeekFunction)], 'GlideDBFunctionBuilder' );
}
// ------------------------------ ----------- ------------------------------------------- -----------
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2018 12:14 AM
Hi,
How can I use an if condition with the glidefunction?
I want to do something like
glidefunction:if(length(name)==1){concat("0",name)}
I am trying to use a function field for a workaround to sort locations correctly. We have racks named 1,2,3,..10,11,12,...20,21,22... Since the name field is a string, it sorts the racks like 1,10,11...2,20,21...3..
Thanks,
Nayanthara