From 10ccc0a2f2cb41cb5effead203f134132a9207cb Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Thu, 16 Apr 2020 21:26:32 +0300 Subject: [PATCH] [SIEM][CASE] Create comments sequentially (#63692) --- .../server/builtin_action_types/servicenow/lib/index.ts | 9 ++++++++- x-pack/plugins/case/server/routes/api/cases/get_case.ts | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/actions/server/builtin_action_types/servicenow/lib/index.ts b/x-pack/plugins/actions/server/builtin_action_types/servicenow/lib/index.ts index 1acb6c563801..cc07a0b90330 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/servicenow/lib/index.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/servicenow/lib/index.ts @@ -147,7 +147,14 @@ class ServiceNow { comments: Comment[], field: string ): Promise { - const res = await Promise.all(comments.map(c => this.createComment(incidentId, c, field))); + // Create comments sequentially. + const promises = comments.reduce(async (prevPromise, currentComment) => { + const totalComments = await prevPromise; + const res = await this.createComment(incidentId, currentComment, field); + return [...totalComments, res]; + }, Promise.resolve([] as CommentResponse[])); + + const res = await promises; return res; } diff --git a/x-pack/plugins/case/server/routes/api/cases/get_case.ts b/x-pack/plugins/case/server/routes/api/cases/get_case.ts index e947118a39e8..ac32b20541a9 100644 --- a/x-pack/plugins/case/server/routes/api/cases/get_case.ts +++ b/x-pack/plugins/case/server/routes/api/cases/get_case.ts @@ -40,6 +40,10 @@ export function initGetCaseApi({ caseService, router }: RouteDeps) { const theComments = await caseService.getAllCaseComments({ client, caseId: request.params.case_id, + options: { + sortField: 'created_at', + sortOrder: 'asc', + }, }); return response.ok({