Query to retrieve pending approvals from a technician account specific (MSSQL)

Query to retrieve pending approvals from a technician account specific (MSSQL)

Tested in build MSSQL (14306)

SELECT wo.WORKORDERID AS "Request ID", 
ad.org_name as "Account",
aaa .first_name as "Technician",
ApprovalStatusDefinition.STATUSNAME AS "Approval Status" FROM WorkOrder wo
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID 
Left Join AAAUser srep ON wos.OwnerID=srep.User_ID
LEFT JOIN WorkOrder_Queue woq ON wo.WORKORDERID=woq.WORKORDERID
 LEFT JOIN QueueDefinition qd ON woq.QUEUEID=qd.QUEUEID 
 LEFT JOIN AccountSiteMapping asm ON wo.SITEID=asm.SITEID 
LEFT JOIN AccountDefinition ad ON asm.ACCOUNTID=ad.ORG_ID 
 left JOIN ApprovalStageMapping ON wo.WORKORDERID=ApprovalStageMapping.WORKORDERID 
LEFT JOIN ApprovalDetails ON ApprovalStageMapping.APPROVAL_STAGEID=ApprovalDetails.APPROVAL_STAGEID 
LEFT JOIN ApprovalStage ON ApprovalDetails.APPROVAL_STAGEID=ApprovalStage.APPROVAL_STAGEID 
LEFT JOIN  approvalstatusdefinition ON ApprovalDetails.STATUSID=ApprovalStatusDefinition.STATUSID
left join sduser sd on sd.userid=ApprovalDetails.approverid
left join aaauser aaa on aaa.user_id=sd.userid
left join workorderaccountmapping wam on wam.workorderid=wo.workorderid
  WHERE ApprovalDetails.ISDELETED!=1 and ApprovalStatusDefinition.STATUSNAME like '%Pending%' and ad.org_name like  '%My Org Inc%'
Group by wo.WORKORDERID,aaa .first_name,ad.org_name,ApprovalStatusDefinition.STATUSNAME ORDER BY 1


Replace the account name as per your account based on your requirement and execute the query.

                  New to ADSelfService Plus?