 
       create temp table tjsm as WITH cte AS
       (
-         SELECT "id","projectId","resourceId","createdAt","statusCode","subscriptionId", "updatedAt", ROW_NUMBER() OVER (PARTITION BY "projectId","resourceId", "statusCode" ORDER BY "createdAt" desc)
+         SELECT "id", "projectId", "resourceId", "createdAt", "statusCode", "subscriptionId", "updatedAt", ROW_NUMBER() OVER (PARTITION BY "projectId", "resourceId", "statusCode" ORDER BY "createdAt" desc)
       AS rn FROM builds WHERE "statusCode" in (4002,4003)
       )
-      SELECT "id","projectId" as pid,"resourceId" as rid,"createdAt","statusCode","subscriptionId", "updatedAt"
+      SELECT "id", "projectId" as pid, "resourceId" as rid, "createdAt", "statusCode", "subscriptionId", "updatedAt"
       FROM cte
       WHERE rn = 1;
 
       create temp table rtjsm as WITH cte AS
       (
-         SELECT "id","projectId","createdAt", "createdBy", "updatedBy","name","typeCode","isJob" FROM resources WHERE "isJob" = true and "typeCode" in (2010,2000,2005,2007,2012,2011,2009)
+         SELECT "id", "projectId", "createdAt", "createdBy", "updatedBy", "name", "typeCode", "isJob", "lastVersionName", "lastVersionNumber" FROM resources WHERE "isJob" = true and "typeCode" in (2010,2000,2005,2007,2012,2011,2009)
       )
-      SELECT "id","projectId" as rpid,"createdAt", "createdBy", "updatedBy","name" as "contextValue","typeCode" as "contextTypeCode"
+      SELECT "id", "projectId" as rpid, "createdAt", "createdBy", "updatedBy", "name" as "contextValue", "typeCode" as "contextTypeCode", "lastVersionName" as "contextDetail", "lastVersionNumber"
       FROM cte;
 
+      update rtjsm set "contextDetail" = rtjsm."lastVersionNumber" where "contextDetail" is null;
+
       -- add required columns to temp table tjsm
-      alter table tjsm add column "contextValue" varchar(255), add column "contextTypeCode" int, add column "lastSuccessfulJobId" varchar(24), add column "lastFailedJobId" varchar(24), add column "createdBy" varchar(24), add column "updatedBy" varchar(24);
+      alter table tjsm add column "contextValue" varchar(255), add column "contextTypeCode" int, add column "contextDetail" varchar(255), add column "lastSuccessfulJobId" varchar(24), add column "lastFailedJobId" varchar(24), add column "createdBy" varchar(24), add column "updatedBy" varchar(24);
 
       -- update contextTypeCode, contextValue
       update rtjsm set "contextTypeCode" = 305 where "contextTypeCode" = 2010;

      update tjsm T set "releaseName" = T."gitTagName" where "isRelease" = true and "releaseName" is null;

      -- update contextTypeCode, contextValue
      update tjsm set "contextTypeCode" = 302, "contextValue" = tjsm."gitTagName" where "isGitTag" = true;
      update tjsm set "contextTypeCode" = 303, "contextValue" = tjsm."releaseName" where "isRelease" = true;
      update tjsm set "contextTypeCode" = 304, "contextValue" = tjsm."pullRequestNumber" where "isPullRequest" = true;
      update tjsm set "contextTypeCode" = 301, "contextValue" = tjsm.bn where "isPullRequest" = false and "isGitTag" = false and "isRelease" = false;
      update tjsm set "updatedBy" = tjsm."createdBy" where "updatedBy" is null;

      -- update lastSuccessfulJobId, lastUnstableJobId, lastTimedoutJobId, lastFailedJobId

      update rtjsm set "contextTypeCode" = 312 where "contextTypeCode" = 2014;
      update rtjsm set "contextTypeCode" = 313 where "contextTypeCode" = 2013;

      update tjsm T1 set "contextValue" = T2."contextValue", "contextTypeCode" = T2."contextTypeCode", "createdBy" = T2."createdBy", "updatedBy" = T2."updatedBy", "contextDetail" = T2."contextDetail" from rtjsm T2 where T1.rid = T2.id;

      -- ignoring records which are not part of (2010,2000,2005,2007,2012,2011,2009) typeCodes
      delete from tjsm where "contextValue" is null;
