# Getting "Error loading primary key data, For input string:"

**URL:** <https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656>\
**Category:** Classic Servoy\
**Created:** [September 30, 2008, 2:38pm UTC](https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656 "2008-09-30T14:38:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![advplee](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@advplee](https://forum.servoy.com/u/advplee)\
**Post date:** [September 30, 2008, 2:38pm UTC](https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656/1 "2008-09-30T14:38:03Z")

</div>

I am getting a “Error loading primary key data, For input string:” error when the program tries to pull in data into a fk field. This error was not present before and the information went in as it was supposed to. I have apparently done something, but I am not sure what. Below I have put all information that I thought would be relevant, but if I need to I will post more info.

Server Information  
Servoy version 3.5.7-build 520, repository version 31  
Current time: Tue Sep 30 10:12:39 EDT 2008  
Uptime: 1 day 10 hours 9 minutes 28 seconds

User Information  
Logged in as: Philip

JDK Information  
java.vm.name=Java HotSpot™ Client VM  
java.vm.version=1.5.0\_13-121  
java.vm.info=mixed mode, sharing  
java.vm.vendor=“Apple Computer, Inc.”

Operating System Information  
os.name=Mac OS X  
os.version=10.4.11  
os.arch=ppc

System Information  
runtime.allocatedMemory=65088K  
runtime.usedMemory=23017K

The database is a Sybase 9 Database.

The method that is calling the import:  
// This method searches the CONTACTS table for matches to apply to buying realtor in the INSPECTION record  
// If an exact match was found, a relation is established to that contact record  
// more than one matches shows a chooser  
//  
// If no matches were found, then any existing link to a contact will be deleted

// remove existing relation to contact  
fk\_buyer\_realtor\_id = null;  
controller.relookup();

// recommit changed changed data (this time calc will stick b/c no related contact to override)  
var new\_value = arguments[1];  
var dp = elements[application.getMethodTriggerElementName()].getDataProviderID();  
controller.setDataProviderValue(dp, new\_value);

// if contact name was deleted or there isn’t sufficient name info, delete any link to contact  
if(!buyer\_lst\_name || !buyer\_fst\_name)  
return;

// get matching contact ids  
var contacts = forms.frm\_insp\_find\_contact\_dlg.find\_contact(buyer\_lst\_name, buyer\_fst\_name);  
if(!contacts)  
return;

// Check Web-Client  
var is\_web\_client = application.getApplicationType() == 5;

// ask user to auto-populate (Not Web Client)  
if(!is\_web\_client){  
var msg = “Matching contact information for a buying realtor was found in the CRM.\n”  
msg += “Would you like to auto-populate the rest of the fields with this information?”;  
var confirm = plugins.dialogs.showQuestionDialog(“Auto-Populate Buying Realtor”, msg, “Yes”, “No”);  
}

// confirmed by user or web client  
if(is\_web\_client || confirm == “Yes”){

// multiple matches  
if(contacts.length \> 1){  
var contact = forms.frm\_insp\_find\_contact\_dlg.show\_chooser();

// action canceled by user  
if(!contact)  
return;

// single hit  
} else {  
var contact = contacts[0];  
}

// create relation  
fk\_buyer\_realtor\_id = contact;  
databaseManager.saveData();  
}

The fk data provider is as follows with the headers in the first row:

Name |Type | Length|Row Ident|Allow Null|Sequence|Properties|  
fk\_buyer\_realtor\_id | Text | 40 | Blank | Yes | None | None |

The data provider that is being pulled in is:

Name |Type | Length|Row Ident|Allow Null|Sequence|Properties|  
id |Text | 40 | pk | No | None | None |

I have looked in Sybase Central and made sure that the properties were consistent and they were. What could have changed that would all of the sudden cause the import not to work anymore? Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [October 1, 2008, 10:50am UTC](https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656/2 "2008-10-01T10:50:59Z")

</div>

Does this error happen every time when running this method? Have you stepped through the method using the debugger? What line causes the error?

---

<div class="post-metadata">

**Author:** ![advplee](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@advplee](https://forum.servoy.com/u/advplee)\
**Post date:** [October 1, 2008, 4:24pm UTC](https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656/3 "2008-10-01T16:24:33Z")

</div>

> Joas:  
> Does this error happen every time when running this method? Have you stepped through the method using the debugger? What line causes the error?

I did that after reading your response. Here is the error message that I got when stepping through the method.

The undefined value has no properties calling getDataProviderID.  
Callstack:  
frm\_insp\_orderform.search\_buyer  
ConversionError: The undefined value has no properties calling getDataProviderID. (search\_buyer; line 14)  
frm\_insp\_orderform.search\_buyer

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [October 1, 2008, 10:23pm UTC](https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656/4 "2008-10-01T22:23:39Z")

</div>

So it is this line that causes the error:

```auto
var dp = elements[application.getMethodTriggerElementName()].getDataProviderID();

```

Put a breakpoint in front of this line and when the debugger reaches that point, find out what the value for “application.getMethodTriggerElementName()” is by using the Evaluate tab.

How is this method triggered? By an onDataChange event? Are you sure that the element that triggers the method is on the same form as the method?

---

<div class="post-metadata">

**Author:** ![advplee](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@advplee](https://forum.servoy.com/u/advplee)\
**Post date:** [October 10, 2008, 3:46pm UTC](https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656/5 "2008-10-10T15:46:39Z")

</div>

The problem appears to be more basic than I thought it was. I tried to import an earlier version of the solution and got this message at the end of the import. “The server version of the column ‘contact\_id’ of table ‘contacts’ in server allows NULL values while the import version does not.” The method that I am getting the original error on was supposed to add the information from one form into another form if there was matching info. So I went to the contact manager and tried to add a new contact by clicking on the new contact button which has the following method:

controller.newRecord();  
elements.tabs.tabIndex = 2;  
forms.mod\_ai\_crm\_contact\_detail\_general.controller.focusFirstField();

and got the following message: “Cannot save form data” I got the details and the details were the following: “com.servoy.j2db.ApplicationException: Cannot save form data com.servoy.j2db.dataprocessing.DataException: ASA Error -95: Column ‘id’ in table ‘contacts’ cannot be NULL”.

I stepped through the method and was taken to this method:

if(globals.shouldAuditLog) //detaults to 1  
{  
var rec = arguments[0];

var tenant = globals.g\_user\_tenant\_id;  
var user = globals.g\_user\_emplyoee\_id;

var tblname = databaseManager.getTable(rec);  
var pkarray = tblname.getRowIdentifierColumnNames();  
var pkname = null;  
var pkvalue = null;

for ( var i = 0 ; i \< pkarray.length ; i++ )  
{  
if (pkname != null)  
{  
pkname = pkname + “;”  
pkvalue = pkvalue + “;”  
}  
pkname = pkname + pkarray\*;\*  
\_ pkvalue = pkvalue + rec[pkarray\*];_\_  
\__ }\*\_

_\* forms.audit\_log.controller.newRecord(true);  
  forms.audit\_log.server\_name = tblname.getServerName();  
  forms.audit\_log.table\_pkname = pkname;  
  forms.audit\_log.table\_name = tblname.getSQLName();  
  forms.audit\_log.table\_pkvalue = pkvalue;  
  forms.audit\_log.tenant\_id = tenant;  
  forms.audit\_log.user\_id = user;  
  forms.audit\_log.action\_type = “insert”  
\__}\*\_  
_The error message comes up when I try to step into the last line in the method._

---

<div class="post-metadata">

**Author:** ![advplee](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@advplee](https://forum.servoy.com/u/advplee)\
**Post date:** [October 15, 2008, 4:37am UTC](https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656/6 "2008-10-15T04:37:53Z")

</div>

Does anybody have any suggestions on this? This is a major issue for my users and I am hopeful somebody here can help with this. Thanks

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [October 15, 2008, 5:59am UTC](https://forum.servoy.com/t/getting-error-loading-primary-key-data-for-input-string/9656/7 "2008-10-15T05:59:31Z")

</div>

You get this error, because you’re trying to save a contact record without the primary key field (id) filled in.  
To solve this, you have to go to your id-column in your table properties and go to “Auto Enter”, there you can select “Servoy sequence”. Make sure that you do “Sync with db” (in Servoy 3.x) or “Calculate from data” (in Servoy 4.x) to make sure that the sequence is up to date, and do “Save” or “Update” afterwards.

If you have done this, your id-field is automatically filled with an increasing integer, and that should keep your db from whining ![:)]( "Smile")
