How to fetch errors from logs in a workflow for triggering mail?

rathikaramamurt
Giga Expert

Hi Team,

I am currently working on an Orchestration workflow, which is used from creating users through SN automation to Active Directory. There is an issue while creating users. i.e., for already existing users, an error is triggered in the logs--> "The specified account already exists"

find_real_file.png

In such cases for Failure, I want to fetch the error from logs in the workflow and notify User (create event OR email notification), about this error "The specified account already exists, submit a new request through General SR form".

Any help wold be greatful!

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Why not check for this in the workflow instead and do a notification activity to the user if the user exits. If not a mail is what you want to happen?



//Göran


View solution in original post

8 REPLIES 8

oharel
Kilo Sage

What happens in the workflow when you get this error?



Harel


Edit: if you have an error in your flow, how about trying this: Workflow Error Handling   , section 4: Creating Error Condition Exits.


You can then create an event activity which will generate a notification in return.


Hi Harel,



Thanks for your inputs.



Please find below screen shot of the workflow triggering the error.


find_real_file.png



From this workflow, I would like to add an event after Run Powershell block, when the state redirects flow to Failure. Please guide me on adding this step.


I tried using the same in my workflow, but while testing the workflow exists through failure and does not reach error stage, for the same error.


find_real_file.png


Hi Rathika,



See below goranlundqvist's suggestion.


You can add an if activity that checks whether the user exists. If it doesn't, move on to user creation. If it does, create an event which will generate a notification.


The if activity script can be something like this:



checkUserExists();


function checkUserExists() {


  var usr = new GlideRecord('sys_user');


  usr.addQuery('user_name', current.SOME_VALUE); //I am not entirely sure what you are sending to the AD to create the user, but of you have some parameters, you can add them here for the script to look in the sys_user table.


  usr.query();



  if(usr.next()) {


    return 'yes';


  } else{


    return 'no';


    }


}



Goran, feel free to suggest something better


harel