How to retrieve approval records based on request milestone in request table?

Certified Lead Developer

HI

I'm working with the following table structures and need to display approval tasks to users based on the current milestone of each request. A task should be shown if the user is either directly assigned or belongs to the assigned group. Each row in Request table has multiple rows in approval table.

Is there a way to achieve this using records (not a database view) given the structure below?

 

CREATE TABLE `table_request` (
  `col_id` INT NOT NULL AUTO_INCREMENT,
  `col_loan_key` VARCHAR(32) DEFAULT NULL,
  `col_loan_1` VARCHAR(32) DEFAULT NULL,
  `col_loan_2` VARCHAR(255) NOT NULL,
  `col_manager` VARCHAR(100) DEFAULT NULL,
  `col_sponsor` VARCHAR(255) DEFAULT NULL,
  `col_milestone` INT DEFAULT NULL,
  `col_status` INT DEFAULT NULL,
  `col_submit_date` DATETIME DEFAULT NULL,
  `col_created_date` DATETIME NOT NULL,
  `col_created_by` VARCHAR(255) NOT NULL,
  `col_updated_date` DATETIME NOT NULL,
  `col_updated_by` VARCHAR(255) NOT NULL,
  `col_is_active` TINYINT(1) NOT NULL,
  PRIMARY KEY (`col_id`),
  KEY `idx_milestone` (`col_milestone`),
  CONSTRAINT `fk_status` FOREIGN KEY (`col_status`) REFERENCES `table_lookup` (`col_lookup_id`) ON UPDATE CASCADE,
  CONSTRAINT `fk_milestone` FOREIGN KEY (`col_milestone`) REFERENCES `table_lookup` (`col_lookup_id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;


CREATE TABLE `table_approval` (
  `col_id` INT NOT NULL AUTO_INCREMENT,
  `col_request_ref` INT NOT NULL,
  `col_created_date` DATETIME NOT NULL,
  `col_updated_date` DATETIME NOT NULL,
  `col_created_by` VARCHAR(255) NOT NULL,
  `col_updated_by` VARCHAR(255) NOT NULL,
  `col_is_active` TINYINT(1) NOT NULL,
  `col_milestone` INT NOT NULL,
  `col_assignment_type` INT DEFAULT NULL,
  `col_approval_key` VARCHAR(100) DEFAULT NULL,
  `col_required_count` TINYINT(2) DEFAULT NULL,
  `col_assigned_date` DATETIME DEFAULT NULL,
  `col_due_date` DATE DEFAULT NULL,
  `col_approver_name` VARCHAR(255) DEFAULT NULL,
  `col_status` INT NOT NULL,
  `col_approval_date` DATETIME DEFAULT NULL,
  PRIMARY KEY (`col_id`),
  KEY `idx_status` (`col_status`),
  KEY `idx_milestone` (`col_milestone`),
  KEY `idx_assignment_type` (`col_assignment_type`),
  CONSTRAINT `fk_status` FOREIGN KEY (`col_status`) REFERENCES `table_lookup` (`col_lookup_id`),
  CONSTRAINT `fk_milestone` FOREIGN KEY (`col_milestone`) REFERENCES `table_lookup` (`col_lookup_id`),
  CONSTRAINT `fk_assignment_type` FOREIGN KEY (`col_assignment_type`) REFERENCES `table_lookup` (`col_lookup_id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

I'm able to achieve the functionality by creating a view in below structure but I want to see if this is achievable using Appian records. Any suggestions would be greatly appreciated.

SELECT
  a.*,  -- All fields from approval table
  b.col_id AS col_request_id,
  b.col_loan_1 AS col_loan_number,
  b.col_loan_2 AS col_loan_type,
  b.col_milestone AS col_request_milestone,
  c.col_value AS col_milestone_label
FROM
  table_approval a
JOIN
  table_request b ON b.col_id = a.col_request_ref
JOIN
  table_lookup c ON a.col_milestone = c.col_lookup_id
WHERE
  b.col_milestone = a.col_milestone
  AND b.col_is_active = 1
  AND a.col_is_active = 1;


Below is some dummy data 

If I login as User_analyst 1 only requests that are assigned to user_analyst1 needs to be displayed to me, But If'm also part of Manager group and director group, I should also see the tasks that are directly assigned to those groups.

Thanks.

  Discussion posts and replies are publicly visible