{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":706,"path":"api-reference/server-api-reference/ActionAPIBoth.md","title":"action - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# action - Scoped, Global\n\nThe action API provides methods to handle data for URLs in a UI action script.\n\nUse this API to configure UI actions with which users can interact. Use these scripts in the UI Action \\[sys\\_ui\\_action\\] table. For information, see [UI actions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/t_EditingAUIAction.md).\n\nMethods for this API are referred to by the variable name 'action' in any server-side JavaScript. To learn more, see [Creating interactions with UI actions](https://developer.servicenow.com/blog.do?p=/post/training-ui-action-101/).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## action - getGlideURI\\(\\)\n\nGets a GlideURI object to determine the user view.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_exr_lfj_nkb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nGlideURI object representing the URI parameter of the user view.-   [GlideURI - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideURIScopedAPI.md)\n-   [GlideURI - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideURIGlobalAPI.md)\n\n**Note:** Any other returned value is considered an error, including null.\n\n</td></tr></tbody>\n</table>The following example shows how to get the user view and set the redirect URL to the service catalog home page.\n\n```\nvar uri = action.getGlideURI();\nvar path = 'catalog_home.do';\n\nuri.set('sysparm_view', 'catalog_default');\naction.setRedirectURL(uri.toString(path));\n```\n\n## action - getReturnURL\\(\\)\n\nGets the URL of the return page in view after a UI action is complete.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|URL of the return page in view after a UI action is complete.|\n\n```\naction.getReturnURL();\n```\n\n## action - getURLParameter\\(String parameterName\\)\n\nGets the value of a URL parameter.\n\n|Name|Type|Description|\n|----|----|-----------|\n|parameterName|String|Name of the URL parameter name to be queried for the URL parameter value.|\n\n|Type|Description|\n|----|-----------|\n|String|URL parameter value.|\n\n```\naction.getURLParameter('sysparm_query');\n```\n\n## action - openGlideRecord\\(Object gr\\)\n\nOpens a page with a GlideRecord in the user view.\n\n|Name|Type|Description|\n|----|----|-----------|\n|gr|[GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)|GlideRecord of the page to be opened in the user view.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to include the caller name and incident description created from an interaction record. For more details, see [Customizing Configurable Workspace with declarative actions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/declarative-actions-landing.md).\n\n```\nif(current.update()){\n  var inc = new GlideRecord(\"incident\");\n  inc.newRecord();\n  inc.caller_id = current.opened_for;\n  inc.short_description = current.short_description;\n  action.openGlideRecord(inc);\n}\n```\n\n## action - setNoPop\\(Boolean noPop\\)\n\nIndicates whether to enable or disable pop-up windows on the page in the current view.\n\n<table id=\"table_mms_gfj_nkb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nnoPop\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag indicating whether to enable or disable pop-up windows on the page:-   true: Disables pop-up windows.\n-   false: Default. Enables pop-up windows.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to disable pop-up windows for a UI action.\n\n```\n\naction.setNoPop(true);\n```\n\n## action - setRedirectURL\\(Object URL\\)\n\nSets the redirect URI for this transaction, which determines the next page the user sees.\n\nFor use cases:\n\n-   [Create a UI routing action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/useful-client-side-scripts.md)\n-   [Create knowledge articles from HR cases](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/ui-action-hrcase-article.md)\n-   [Task relationships with UI actions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_UIActions.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|URL|Object|URL to set as the redirect. You can provide the URL as a string or a [GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md). If you pass the URL as a GlideRecord, this value takes the focus to that record's form.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to redirect a user to a URL from a UI action using the [current](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_ScriptableServiceCatalogVariables.md) variable.\n\n```\nvar fixchg = new GlideRecord(\"change_request\");\nfixchg.short_description= current.short_description;\nfixchg.comments= current.comments.getHTMLValue();\n// fixchg.parent = current.sys_id;\nfixchg.insert();\nFixChange();\n \ngs.addInfoMessage(\"Change \"+ fixchg.number+\" created\");\naction.setRedirectURL(current);\naction.setReturnURL(fixchg);\n \nfunction FixChange(){\nvar m2m = new GlideRecord('task_rel_task');\nm2m.initialize();\nm2m.child= current.sys_id;\nm2m.parent= fixchg.sys_id;\nm2m.type.setDisplayValue(\"Fixes::Fixed by\");\nm2m.insert();}\n```\n\nThe following example shows how to create a new incident record and redirect to the new incident after a UI action completes.\n\n```\nvar reqItem = current.u_item;\nvar requestedFor = current.u_requested_for;\nvar location = current.location;\n\nif(current.u_incident_request == 'Incident'){\n  //Create a new incident record and redirect to the new incident\n  var rec = new GlideRecord('incident');\n  rec.initialize();\n  rec.caller_id = requestedFor;\n  rec.location = location;\n  rec.insert();\n  action.setRedirectURL(rec);\n}\n\nif(current.u_incident_request == 'Request'){\n  //Build the url and route the user to the request item\n  var url = '';\n  if(current.u_item.sys_class_name == 'sc_cat_item_guide'){\n    url = 'com.glideapp.servicecatalog_cat_item_guide_view.do?sysparm_initial=true&sysparm_guide=' + \n      reqItem + '&sysparm_user=' + requestedFor + '&sysparm_location=' + location;\n  }\n  else{\n    url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqItem + '&sysparm_user=' +  \n      requestedFor + '&sysparm_location=' + location;\n  }\n  action.setRedirectURL(url);\n}\n```\n\n## action - setReturnURL\\(Object URL\\)\n\nSets the return URI for this transaction after a UI action is complete. You can use this method to determine what page the user has in view when they return from submit.\n\n|Name|Type|Description|\n|----|----|-----------|\n|URL|Object|URI to set as the return location after a UI action is complete. You can provide the URL as a string or a [GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example enables the user to select the UI action to create a change record using information from the problem record and the change template. After the change, the user returns to [current](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_ScriptableServiceCatalogVariables.md) view. For more information, see [Scripted templates](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_ScriptedTemplates.md). For more use cases, see [Task relationships with UI actions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_UIActions.md).\n\n```\nvar change = new GlideRecord(\"change_request\");\nchange.initialize();\nchange.short_description = current.short_description;\nchange.description = current.u_details;\nchange.cmdb_ci = current.u_service;\nchange.priority = current.priority;\nchange.requested_by = current.caller_id;\nchange.assignment_group.setDisplayValue('Change & Release');\nchange.u_status = 'New';\nchange.parent = current.number;\nchange.applyTemplate(\"standard_rfc\");\ncurrent.rfc = change.insert();\ncurrent.comments = 'Change ' + change.number + ' created.';\n\nvar mySysID = current.update();\n\ngs.addInfoMessage(\"Change \" + change.number + \" created\");\naction.setRedirectURL(change);\naction.setReturnURL(current);\n```\n\n## action - setURLParameter\\(String parameterName, String parameterValue\\)\n\nSets a URL parameter name and value.\n\n|Name|Type|Description|\n|----|----|-----------|\n|parameterName|String|Name of the URL parameter.|\n|parameterValue|String|Value of the parameter.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\naction.setURLParameter('sysparm_query', 'priority=2^active=true');\n```\n\n"}}