Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { axios } from "@pipedream/platform";
import servicenow from "../../servicenow.app.mjs";

export default {
key: "servicenow-get-current-user",
name: "Get Current User",
description: "Returns the authenticated ServiceNow user's sys_id, name, email, username, and instance URL. Call this first when the user says 'my incidents', 'my cases', 'assigned to me', or needs their ServiceNow identity. Use `sys_id` to filter records in **Get Table Records** (e.g. `assigned_to={sys_id}`) or **Create Table Record**. [See the documentation](https://docs.servicenow.com/bundle/vancouver-api-reference/page/integrate/inbound-rest/concept/c_TableAPI.html).",
version: "0.0.1",
version: "0.0.2",
type: "action",
annotations: {
destructiveHint: false,
Expand All @@ -16,31 +15,30 @@ export default {
servicenow,
},
async run({ $ }) {
const sessionInfo = await axios($, {
url: `${this.servicenow.baseUrl()}/api/now/ui/user/current_user`,
headers: this.servicenow.authHeaders(),
const sessionInfo = await this.servicenow._makeRequest({
$,
url: "/ui/user/current_user",
});

const userSysId = sessionInfo.result?.user_sys_id;
const userSysId = sessionInfo?.sys_id;

if (!userSysId) {
throw new Error("Unable to determine current user from session");
}

const userResponse = await axios($, {
url: `${this.servicenow.baseUrl()}/api/now/table/sys_user/${userSysId}`,
headers: this.servicenow.authHeaders(),
const user = await this.servicenow._makeRequest({
$,
url: `/table/sys_user/${userSysId}`,
params: {
sysparm_fields: "sys_id,user_name,name,email,title,department,location",
},
});

const user = userResponse.result;
const summaryName = user.name || user.user_name || user.sys_id;
$.export("$summary", `Retrieved user ${summaryName}`);

return {
instance_url: this.servicenow.baseUrl(),
instance_url: `https://${this.servicenow.$auth.instance_name}.service-now.com`,
sys_id: user.sys_id,
user_name: user.user_name,
name: user.name,
Expand Down
2 changes: 1 addition & 1 deletion components/servicenow/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/servicenow",
"version": "0.10.1",
"version": "0.10.2",
"description": "Pipedream ServiceNow Components",
"main": "servicenow.app.mjs",
"keywords": [
Expand Down
Loading