Service Desk Practitioners Forum
cancel

Error while creating a new Person on SD 4.5 SP 19 via web-api

Highlighted
Alex Burgess
New Member.

Error while creating a new Person on SD 4.5 SP 19 via web-api

Hi there,

I'm trying to create a new Person via the web-api. But I'm getting constantly the following error on setting the telephone number:

java.lang.RuntimeException: You are not allowed to view this person or this may have been deleted by another user.

Here is an explanation of what I'm doing or have done so far. First thing is to create a new IPerson "object" through the following line of code:

final IPerson person = session.getPersonHome().openNewPerson();

This works fine. After that I'm checking if I can modify the person (=isModifyAllowed()) and that also works fine and tells me I'm allowed too. Then I go on and set some fields like Location, Organization, Email, Name, texts and shorttexts and that still works pretty fine. But when it comes to setting the telephone number I'm always getting the error mentioned above. I tried setting the number with the following solutions so far (always the same error):

1) person.setPrimaryTelephoneNumber( "123" );

2) person.setPrimaryTelephoneNumber( organizationPhone.getNumber() );

3) person.addTelephone( organizationPhone );

4) ITelephone newPhone = session.getTelephoneHome().openNewTelephone();
newPhone.set...
person.addTelephone( newPhone );
(the last one with using information retrieved from an existing Organization ITelephone instance -> comparable to the second example )
or
4.1) newPhone.setPerson( person )

Ok, after catching this Exception I'm still trying to save the person (person.save()) but then I'm getting the following error:

java.lang.RuntimeException: For person the following fields are required:

telephone number.

This seems reasonable as I'm not allowed the set the telephone number or at least not able to. My customer told me, that the user I'm using to run the program is allowed to do all that stuff. After finding this Exception on save I'm cancelling the creation of the person (person.cancel()).

I'm relativley new to the system so probably I might lack some knowledge, but these are my questions:

1. Am I doing something wrong? Are there other ways of setting the phone number?
2. Is it possible that the user I am using might have the rights for the other fields but not for the field "telephone number"?
3. Is the requirement, to set the field "telephone number", some kind of system default or might this be enforced by some database rule of my customer? (which then should be softened or changed)
4. In one post I read that setting a phone number for example by person.setPrimaryTelephoneNumber( numberString ) actually will make a look up in the phone table of the database for the "numberString". Then, if it finds such a number, would use some sort of ID to reference it or else create a new entry for that phone in the table and use that ID. Is it then possible that my user account might not have the rights to read the phone table or write to it?
5. Another possibility I read, was that you should save the person before setting the telephone number but that's not possible for me. Is it true that a person must be saved prior to setting a phone number?
6. It seems that on some fields, you should still save the item and then do some kind of update or the system will do the missing stuff on its own. Should I not cancel the person and by this hope that anything "magical" will happen?
7. Might this be some kind of bug? If so, are there any known solutions to it?

SD version: 4.5 SP19
JRE: 1.6.0_5 or higher

I hope this is all the information you need. If you need anything else let me know.

Thanks
2 REPLIES
Alexander Kriku
Honored Contributor.

Re: Error while creating a new Person on SD 4.5 SP 19 via web-api


hi

first of all it's better to check the access rights of the account you are using.

try to log to the system via client application using login and password from your script and then check whether you can modify the phone number
Vasily Kamenev
Acclaimed Contributor.

Re: Error while creating a new Person on SD 4.5 SP 19 via web-api

Hi
After you set phone, need mark tel. as primary and then primary tel. # must be set as primary # -> person.setPrimaryTelephoneNumber("123")

Vasily