Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAI-13429 - ServiceNow improvements #1731

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 25 additions & 12 deletions sources/servicenow-source/src/servicenow/servicenow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export class ServiceNow {
sys_updated_on = this.cutOff,
pageSize = this.config.page_size ?? DEFAULT_PAGE_SIZE
): AsyncGenerator<Incident, any, any> {
let hasNext = false;
let hasNext: boolean;
let offset = 0;
let query;
let query: string;

if (sys_updated_on) {
this.logger.info(`Syncing incidents updated since: ${sys_updated_on}`);
Expand All @@ -106,9 +106,15 @@ export class ServiceNow {
query
);
} catch (err: any) {
this.logger.error(`Error retrieving incidents: ${err.message}`);
this.logger.error(`Will resume processing from here next sync...`);
break;
if (offset > 0) {
this.logger.error(
`Error retrieving users after successful calls: ${err.message}`
);
this.logger.error(`Will resume processing from here next sync...`);
break;
} else {
throw err;
}
}

if (incidents?.length) {
Expand Down Expand Up @@ -140,7 +146,6 @@ export class ServiceNow {
) {
const business_service_sys_id = incident.business_service.value;
// If sys_id previously seen, retrieve name from map
console.log(business_service_Map);
if (business_service_Map.has(business_service_sys_id)) {
business_service_identifier = business_service_Map.get(
business_service_sys_id
Expand Down Expand Up @@ -209,13 +214,15 @@ export class ServiceNow {
sys_updated_on?: string,
pageSize = this.config.page_size ?? DEFAULT_PAGE_SIZE
): AsyncGenerator<User, any, any> {
let hasNext;
let hasNext: boolean;
let offset = 0;
let query;

let query = 'ORDERBYsys_updated_on';
if (sys_updated_on) {
this.logger.info(`Syncing users updated since: ${sys_updated_on}`);
query = `sys_updated_on>=${sys_updated_on}`;
query += `^sys_updated_on>${sys_updated_on}`;
}

do {
hasNext = false;
let users: User[];
Expand All @@ -226,9 +233,15 @@ export class ServiceNow {
query
);
} catch (err: any) {
this.logger.error(`Error retrieving users: ${err.message}`);
this.logger.error(`Will resume processing from here next sync...`);
break;
if (offset > 0) {
this.logger.error(
`Error retrieving users after successful calls: ${err.message}`
);
this.logger.error(`Will resume processing from here next sync...`);
break;
} else {
throw err;
}
}

if (users?.length) {
Expand Down
2 changes: 1 addition & 1 deletion sources/servicenow-source/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('index', () => {
}
expect(listUsers.mock.calls.length).toBe(1);
expect(listUsers.mock.calls[0][1]).toBe(
`sys_updated_on>=${sys_updated_on}`
`ORDERBYsys_updated_on^sys_updated_on>${sys_updated_on}`
);
});

Expand Down