import { NativeArray } from "../imports/NativeArray"; import { NativeObject } from "../imports/NativeObject"; import { Scriptable } from "../imports/Scriptable"; import { GlideElement } from "./GlideElement"; import { GlideRecord } from "./GlideRecord"; /** * The server-side scripting helper $sp is a collection of methods * for developing Service Portal widgets such as getting a widget * instance record, getting a JSON-formatted record, or checking * if a user can access a record. */ export declare class GlideSPScriptable { /** * The server-side scripting helper $sp is a collection of methods * for developing Service Portal widgets such as getting a widget * instance record, getting a JSON-formatted record, or checking * if a user can access a record. */ constructor(); constructor(portalID: string); /** * Returns the GlideRecord for the current widget instance. */ getPortalRecord(): GlideRecord; /** * Returns the GlideRecord for the current widget instance with no parameters or * the specified record with (table,sys_id) or (table,GlideElement). */ getRecord(): GlideRecord; getRecord( table: string, sys_id: string, applyDataFilters?: boolean ): GlideRecord; getRecord(table: string, ge: GlideElement): GlideRecord; /** * Returns the widget's parameters as an object. */ getWidgetParameters(): Scriptable; /** * Get a value in this order: From the request. * From the sp_instance record. From the sp_portal record. */ getValue(name: string): any; /** * Get a display value in this order: From the request. * From the sp_instance record. From the sp_portal record. */ getDisplayValue(name: string): string; /** * Get values from the sp_instance record and copy them into 'data'. * Pass comma-separated 'names' to get values from specific fields. */ getValues(data: Scriptable, names?: string): void; /** * Copies values for the specified field names into the data parameter. */ getRecordValues(data: Scriptable, from: GlideRecord, names: string): void; /** * Copies display values for the specified field names into the data parameter. */ getRecordDisplayValues( data: Scriptable, from: GlideRecord, names: string ): void; /** * Copies the element name, display value, and * value for the specified field names into the data parameter. */ getRecordElements(from: GlideRecord, names: string): NativeObject; getRecordElements(data: Scriptable, from: GlideRecord, names: string): void; /** * Get the specified widget instance. Used for including a widget inside * another widget (such as a menu inside header). */ getWidgetScope(instanceID: string): Scriptable; /** * Returns a widget from the specified widget instance. */ getWidgetFromInstance(instanceID: string): Scriptable; /** * Deprecated. Copy of getWidgetFromInstance. */ getWidgetFromRectangle(instanceID: string): Scriptable; /** * Used for including a widget inside another widget without an instance. * Such as $sp.getWidget('widget_id', {p1: param1, p2: param2});. */ getWidget(widgetID: string, widgetParams?: any): Scriptable; /** * Get all data from 'tableName' where 'foreignKey' matches this widget * instance sys_id. Used by the carousel widget. */ getRelatedList(tableName: string, foreignKey: string): NativeArray; /** * Returns the value of the specified parameter for the * Request or the Widget instance. */ getParameter(name: string): any; /** * Returns the table's variables as a string. */ getVariables(includeNilResponses?: boolean): string; /** * Returns the record's task variables. */ getRecordVariables(gr: GlideRecord, includeNilResponses?: boolean): string; /** * Returns the table's variables as an object. */ getVariablesArray(includeNilResponses?: boolean): Scriptable; /** * Returns the record's variables. */ getRecordVariablesArray( gr: GlideRecord, includeNilResponses?: boolean ): Scriptable; /** * Get a record's activity stream as a JSON formatted list. * Typically for a task record. */ getStreamEntries(): string; /** * Get the activity stream for the widget instance or the specified table or record. */ getStream(): Scriptable; getStream(table: string, sys_id: string): Scriptable; /** * Returns the list of columns for the specified table and view. * Uses the mobile view when no view is specified. */ getListColumns(tableName: string, view?: string): Scriptable; /** * Get the current user's initials. */ getUserInitials(): string; /** * Get a simple object containing {label, value, display value, type} * from a GlideRecord by field name. */ getField(gr: GlideRecord, name: string): Scriptable; /** * Like getField but returns an array of field objects for each comma separated field name. */ getFields(gr: GlideRecord, names: string): Scriptable; /** * Like getField but returns a map of {fieldName: fieldObj, ...} * for each comma separated field name. */ getFieldsObject(gr: GlideRecord, names: string): Scriptable; /** * Returns an array of objects where each object contains the * breadcrumb label, value, and flags for if fixed and if removed. */ getFilterBreadcrumbs( table: string, query: string, fixedQuery: string ): NativeArray; /** * Adds a record to the Service Portal statistics log. */ static logStat( type: string, table: string, id: string, text?: string, portalId?: string ): void; /** * Adds a record to the Service Portal statistics log. */ static logSearch( table: string, terms: string, count: number, searchType?: string, portal?: string, page?: string ): void; /** * Determines if the user is allowed to see the specified page. */ static canSeePage(pageID: string): boolean; /** * Returns true if a record is valid and GlideRecord.canRead() returns true. * Accepts (table_name, sys_id) or (glideRecord). */ canReadRecord(gr: GlideRecord): boolean; canReadRecord(table: string, id: string): boolean; /** * Get the fields and view definition of a sc_cat_item or * sc_cat_item_guide. Used to build a catalog item form. */ getCatalogItem(data: Scriptable): Scriptable; getCatalogItem( itemID: string, isOrdering?: boolean, tableName?: string ): Scriptable; /** * Get the fields and view definition of a sc_cat_item or * sc_cat_item_guide. Used to build a catalog item form. */ getGuide( itemID: string, isOrdering: boolean, addIncludedItems: boolean ): Scriptable; /** * Get the form and view from a table record, encoded query, and requested view. */ getForm( table: string, sys_id: string, encodedQuery?: string, view?: string, isPopup?: boolean, includeScripts?: boolean ): Scriptable; /** * Saves or updates the specified record. */ saveRecord(table: string, sys_id: string, model: Scriptable): Scriptable; /** * Saves variables of a Table (table, sys_id). */ saveVariables(table: string, sys_id: string, model: Scriptable): Scriptable; /** * Returns KB articles in the specified category and its subcategories. * Pass 'limit' to limit the number of articles returned. */ getKBCategoryArticles(category: string, limit?: number): Scriptable; /** * Returns KB article summaries in the specified category and its subcategories. 'limit' is the max * number of articles to return. 'maxChars' is the max length of the article summary. */ getKBCategoryArticleSummaries( category: string, limit: number, maxChars: number ): Scriptable; /** * Returns KB article summary in the specified category, excludes subcategories. */ getKBCategoryArticleSummary( category: string, limit: number, maxChars: number ): Scriptable; /** * Returns KB categories with the same parent as the specified category. */ getKBSiblingCategories(catID: string): GlideRecord; /** * Returns the number of Knowledge Base articles */ getKBCount(kbIDs: string): number; /** * Returns the KB subcategories of the specified category. */ getSubCategories(catId: string): GlideRecord; /** * Returns the top category in the hierarchy containing the specified category. */ getKBTopCategoryID(catId: string): string; /** * Returns portal's KB record where the workflow state is published. */ getKBRecord(): GlideRecord; /** * Returns all KB records for the specified knowledge bases. */ getAllKBRecords(kbIDs: string): GlideRecord; /** * Returns the portal's service catalog record where the class is not * a Content Item or Wizard Launcher and the state is active. */ getSCRecord(): GlideRecord; /** * Removes non-breaking spaces from the specified string. */ stripHTML(html: string): Scriptable; /** * Returns the menu items for the specified widget instance. */ getMenuItems(sys_id: string): Scriptable; /** * Builds the href portion of the URL (the value after ?id=) * for the specified page. */ getMenuHREF(gr: GlideRecord): Scriptable; /** * Returns the widget instance's GlideRecord. */ getInstanceRecord(): GlideRecord; /** * Returns the values associated with the portal's specified CSS parameters. */ buildThemeVariableModel(portalId: string, names: string): Scriptable; /** * Returns the widget's sys_id. */ getWidgetSysId(): string; /** * Returns the active taxonomies configured for the current portal. */ getTaxonomies(): string; /** * Returns the assessment record. */ getAssessmentRecord( assessmentId: string, typeId: string, data: Scriptable ): Scriptable; /** * Returns the Service Portal vlist actions for the given sysId. */ getSPVlistActions(sysId: string): Array; /** * Returns the type of the Announcement. */ getAnnouncementConsumerType(typeIds: string[]): Record; /** * Helper method to get the current User consent details of a User. */ getUserTrackingDetails(): any; /** * Returns true if the table is accessible to the public. */ hasPublicAccessToTable( table: string, widgetOptions: any, widgetInput: any ): boolean; /** * Returns the UI scripts version map as a JSON string. */ getUiScriptsVersionMap(): string; /** * Get the search application configuration for the portal when now assist is enabled. */ getSearchApplicationConfigForNASSEnabledPortal(): string; /** * Returns true if the table should use ES Latest. */ shouldUseESLatest(tableName: string, sysId: string): boolean; /** * Returns the user's preferred communication channels. */ getUserPreferredChannels(): string; /** * Returns true if the table has a text index. */ hasTextIndex(tableName: string): boolean; /** * Check if AI Search is enabled on portal record. */ isAISearchEnabled(): boolean; /** * Check if Chat Assistant is enabled for the portal. */ isChatAssistantEnabled(): boolean; /** * Check if dark theme is enabled on portal record. */ isDarkThemeEnabledInPortal(): boolean; /** * Check if Dynamic Chat Assistant is enabled for the portal. */ isDynamicChatAssistantEnabled(): boolean; /** * Check if Now Assist is enabled for the portal. */ isNowAssistEnabled(): boolean; /** * Returns true if RTL is enabled for the portal. */ isRTLEnabled(): boolean; /** * Returns true if the input URL is a Service Portal URL. */ isServicePortalURL(inputURL: string): boolean; /** * Returns true if user criteria is enabled. */ isUserCriteriaEnabled(): boolean; /** * Sends the specified message to the console log. */ log(message: any): void; /** * Maps a URL to a Service Portal URL. */ mapUrlToSPUrl(url: string): string; /** * Returns true if the portal has chat config. */ portalHasChatConfig(portalId: string): boolean; /** * Publishes search analytics with the given payload string. */ publishSearchAnalytics(payloadString: string): void; /** * Returns true if catalog prices should be shown. */ showCatalogPrices(): boolean; /** * Returns true if the price should be shown. */ showPrice(price: number): boolean; /** * Returns true if the recurring price should be shown for the given frequency. */ showRecurringPrice(price: number, freq: string): boolean; /** * Translates the given template string. */ translateTemplate(input: string): string; /** * Returns true if the user can see the search source by criteria. */ userCanSeeSearchSourceByCriteria(searchSourceID: string): boolean; }