cancel
Showing results for 
Search instead for 
Did you mean: 

Error handling in a Personas Script for an RFC

former_member195355
Participant
0 Kudos

Hi,

I have the following code, that I am testing for failure, which tries to retrieve a user's personnel number:

I thought the IF statement would be enough for handling errors but I get this error message when I run the code:

I'm struggling to see what to do next. Would any of you smart people have any ideas?

Thanks

View Entire Topic
bwills
Contributor

Hi Robert,

It seems the Remote Function Module that you are using has an exceptions section. What is happening is this. When an invalid user id is submitted the function module is going to an Exception and that bascially crashes the function module and hence you do not get proper results.

Instead use this function module: "BAPI_USR01DOHR_GETEMPLOYEE". This does not use exception handling and will give you a proper return. See the code below.

var uname = session.info.user;
var oRFC = session.createRFC("BAPI_USR01DOHR_GETEMPLOYEE");
oRFC.setParameter("ID", uname);
oRFC.requestResults(["EMPLOYEENUMBER","RETURN"]);
oRFC.send();
var _EMPLOYEENUMBER = oRFC.getResult("EMPLOYEENUMBER");
var _RETURN = oRFC.getResultObject("RETURN");

session.utils.log('employee number: ' + _EMPLOYEENUMBER);
session.utils.log('return.ID = ' + _RETURN.ID);
session.utils.log('return.MESSAGE = ' + _RETURN.MESSAGE);

if(_EMPLOYEENUMBER === '00000000')
{
    session.utils.log('No employee number found for the user');
    return;
}

Don't forget to add the Function Module to the allow FM list.

Let me know if you have any issues with this.

Cheers,

Brian

former_member195355
Participant

That's brilliant, thanks very much Brian!