Writing custom script in the virtual attribute in Sync editor

Hello,

I am using the following custom script in the virtual attribute to find out managers -> PersonnelNumber and map it to another database column. But I am not able to successfully do that. could someone help me where I am doing it wrong.

This is the script that I am using to read personhead's personnelnumber.

Imports VI.Projector.Connection

Dim Personobj As ISystemObject = SystemObject.Connection.QueryObject(SystemQuery.From("Person").Select("PersonnelNumber").Filter(String.Format("UID_person='{0}'", $UID_PersonHead$))).Result.FirstOrDefault

If Not Personobj Is Nothing Then

If String.IsNullOrEmpty(Personobj.GetValue("PersonnelNumber").AsString) Then

Return Personobj.GetValue("PersonnelNumber").AsString

Else

Return ""

End If
Else
Return ""
End If

Product Version = 8.1

Thanks in Advance.