Service Desk Practitioners Forum
cancel

Clearing Person's TelephoneNumber using webapi not possible?

SOLVED
Go to solution
Highlighted
Mark Teichmann
Super Contributor.

Clearing Person's TelephoneNumber using webapi not possible?

One problem of data imports into SD 4.5 is that fields are not cleared automatically. E.g. if a user no longer owns a telephone and we put an empty field in the upload file then his former phone number still remains in his person entry in CMDB.
Therefore I would like to clear the field programmatically using the webapi. While it is no problem to delete the Telephone objects of the person I cannot get it to work with clearing the computed field 'Telephone number' which holds the Primary phone number of the person. When removing the Telephone object in the SD client then this field is automatically cleared. Is it possible to let this happen via webapi also?
In the moment we use dummy characters ('+' for an empty number) in order to see only active phone numbers in CMDB but this is only a workaround.
4 REPLIES
Mike Bush
Acclaimed Contributor.

Re: Clearing Person's TelephoneNumber using webapi not possible?

This seems odd, I would expect the deletion of a Telephone record to trigger the clearance of the Person field? Is it possible that you need to SAVE the Person record after deleting the phone - perhaps code HAS tried to clear the field but you need to acknowledge the update?
Mark Teichmann
Super Contributor.

Re: Clearing Person's TelephoneNumber using webapi not possible?

Unfortunately saving the person ends up in person entries where no Telephone objects are related but the value in the field 'TelephoneNumber' is still present.
Maybe I have to create a rule that clears this field as soon as no Telephone object is available but I would not like to mingle webapi programming with database rules' logic.
Christian Nilss
Super Contributor.
Solution

Re: Clearing Person's TelephoneNumber using webapi not possible?

I tried this, im not sure if it's solves your problem...

1. clear the phone attribute value of the person record.
2. Delete the phone object from the person object.

...
IPerson[] person = session.getPersonHome()
.searchOnName("Johnson, Martin");
ITelephone[] ph = person[0].getTelephone();
ph[0].setNumber(" ");
ph[0].save();
// deletion of phone record
ITelephone[] ph2 = person[0].getTelephone();
ph2[0].delete();
...

regards
christian
Mark Teichmann
Super Contributor.

Re: Clearing Person's TelephoneNumber using webapi not possible?

This only is a workaround but at least it works. (The field Telephone number is still not empty but filled with a space character while it is empty if you remove the Phone object in the SD client)
You did not need to retrieve the phone using different objects. Simply using the following code works:
ITelephone[] telephones = telephoneHome.searchOnPerson(person);
if (phone.equals("") && telephones != null) {
try {
ITelephone telephone = telephones[0];


telephone.setNumber(" ");

telephone.save();

telephone.delete();
}