Try this one. I removed references to the orgid to make space (but only in the new code). This assumes you don't have the same site in more than one org (not sure that is allowed).
I don't have all those modules so I can't test in mine but I think the SQL is correct. If not, look at the paranthesis past you PLUSCDSSTATUS
doclinksid in (select doclinksid from doclinks where (ownertable='WORKORDER' and ownerid=:workorderid) UNION ALL select doclinksid from doclinks where (ownertable='WORKORDER' and ownerid in (select workorderid from workorder where parent=:wonum and istask=1 and siteid=:siteid)) UNION ALL select doclinksid from doclinks where (ownertable='ASSET' and ownerid in (select assetuid from asset where assetnum=:assetnum and siteid=:siteid)) UNION ALL select doclinksid from doclinks where (ownertable='LOCATIONS' and ownerid in (select locationsid from locations where location=:location and siteid=:siteid)) UNION ALL select doclinksid from doclinks where (ownertable='JOBPLAN' and ownerid in (select jobplanid from jobplan where jpnum=:jpnum and (siteid is null or siteid=:siteid) and pluscrevnum =:pluscjprevnum) ) UNION ALL select doclinksid from doclinks where (ownertable='PM' and ownerid in (select pmuid from pm where pmnum=:pmnum and siteid=:siteid)) UNION ALL select doclinksid from doclinks where (ownertable='SAFETYPLAN' and ownerid in (select safetyplanuid from safetyplan,wosafetyplan where safetyplan.safetyplanid=wosafetyplan.safetyplanid and wosafetyplan.wonum=:wonum and wosafetyplan.siteid=:siteid)) UNION ALL select doclinksid from doclinks where (ownertable in ('SR','INCIDENT','PROBLEM') and ownerid in (select ticketuid from ticket,relatedrecord where ticketid=recordkey and ticket.class = relatedrecord.class and relatedrecclass=:woclass and relatedreckey=:wonum and relatedrecsiteid=:siteid)) UNION ALL select doclinksid from doclinks where (ownertable in ('WOCHANGE','WORELEASE','WOACTIVITY') and ownerid in (select workorderid from workorder,relatedrecord where wonum=recordkey and workorder.woclass = relatedrecord.class and relatedrecclass=:woclass and relatedreckey=:wonum and relatedrecsiteid=:siteid)) UNION ALL select doclinksid from doclinks where (ownertable='COMMLOG' and ownerid in (select commloguid from commlog where ownerid=:workorderid and ownertable in (:&synonymlist&_WOCLASS[ACTIVITY,CHANGE,RELEASE,WORKORDER]))) UNION ALL select doclinksid from doclinks where (ownertable='SLA' and ownerid in (select slaid from sla,slarecords,workorder where sla.slanum=slarecords.slanum and slarecords.ownerid=workorder.workorderid and sla.objectname='WORKORDER' and slarecords.ownertable='WORKORDER' and workorder.wonum=:wonum)) UNION ALL select doclinksid from doclinks where (ownertable='PLUSDSPLAN' and ownerid in (select plusdsplanid from plusdsplan where (siteid is null or siteid=:siteid) and status in (select value from synonymdomain where (siteid is null or siteid=:siteid) and domainid = 'PLUSCDSSTATUS' and maxvalue = 'APPR') and dsplannum in (select dsplannum from pluscwods where wonum=:wonum and siteid=:siteid)) UNION ALL select doclinksid from doclinks where OwnerTable = 'INSPFIELDRESULT' AND ownerid in (SELECT InspFieldResult.InspFieldResultID FROM MAXIMO.InspFieldResult INNER JOIN MAXIMO.INSPECTIONRESULT ON InspFieldResult.RESULTNUM = INSPECTIONRESULT.RESULTNUM AND InspFieldResult.SITEID = INSPECTIONRESULT.SITEID WHERE INSPECTIONRESULT.siteid=:siteid and (((INSPECTIONRESULT.REFERENCEOBJECTID=:WONUM or INSPECTIONRESULT.PARENT=:WONUM ) and INSPECTIONRESULT.REFERENCEOBJECT = 'WORKORDER') OR (INSPECTIONRESULT.REFERENCEOBJECTID=:WONUM and INSPECTIONRESULT.REFERENCEOBJECT = 'PARENTWO') OR (INSPECTIONRESULT.PARENT=:WONUM and INSPECTIONRESULT.REFERENCEOBJECT = 'WOACTIVITY') OR (INSPECTIONRESULT.PARENT=:WONUM and INSPECTIONRESULT.REFERENCEOBJECT='MULTIASSETLOCCI') OR (INSPECTIONRESULT.fupobject='WORKORDER' AND INSPECTIONRESULT.FUPOBJECTID=:WONUM)) union SELECT InspFieldResult.InspFieldResultID FROM MAXIMO.InspFieldResult where (INSPQUESTIONNUM,INSPFORMNUM ,REVISION,RESULTNUM,SITEID,orgid) in (SELECT INSPQUESTIONNUM,INSPFORMNUM ,REVISION,RESULTNUM,SITEID,orgid FROM MAXIMO.InspFieldResult where InspFieldResult.fupobject='WORKORDER' AND InspFieldResult.FUPOBJECTID=:WONUM and InspFieldResult.siteid=:siteid)))