Thursday, 29 March 2018

OIM API - Code Snippet to get ProcessInstanceKey by ApplicationInstanceName and UserKey.

  public String getProcessInstanceKey(String userKey, String appInstName){
       final String logp = CN + " :: getProcessInstanceKey - ";
       logger.info(logp + "START");

       ProvisioningService provServOps = Platform.getService(ProvisioningService.class);
      
       String procInstKey = null;
       List<Account> accountList = null;
       try{
           accountList = provServOps.getAccountsProvisionedToUser(userKey);
          
           for(Account account : accountList){
           if ((account.getAppInstance().getApplicationInstanceName().equalsIgnoreCase(appInstName)) &&
               ((account.getAccountStatus().equalsIgnoreCase("Provisioned")) ||
                account.getAccountStatus().equalsIgnoreCase("Enabled"))){
                   logger.info(logp + "Account is Provisioned/Enabled");
                   if((Account.ACCOUNT_TYPE.Primary).equals(accountprovisioned.getAccountType())){
                       logger.info(logp + "Account is Primary");
                       procInstKey = account.getProcessInstanceKey();


                       logger.info(logp + "procInstKey : " + procInstKey);
                   }
               }
           }
       }catch(Exception e){
           logger.error(logp + "Exception while getting IT Process Instance Key for - " + e, e);
       }
       logger.info(logp + "END");
       return procInstKey;
  }


Happy Learning!!!

No comments:

Post a Comment