with key 0 was not found when inserting new record to list

with key 0 was not found when inserting new record to list

  

Hi, I am facing the error ""OSUR_xxx_Skill" with key 0 was not found" when adding a new row into the list and the table "ABC" in the error is reference table. The error is thrown at ListInsert action where adding new row to the list. And the reference column is bound to combo box. Please find the below trace log and advise for the fix. Thanks in advance.

 at ssHRManagement.ExtendedActions.GetSkill(HeContext heContext, Int32 inParamId, RCSkillRecord& outParamRecord)
   at ssHRManagement.Functions.ssGetSkill(HeContext heContext, Int32 inParamId)
   at ssHRManagement.Flows.FlowMainFlow.ScrnSkillSetPopover.expressionCompType()
   at ASP.skillsetpopover_aspx.__DataBind__control65(Object sender, EventArgs e)
   at System.Web.UI.Control.OnDataBinding(EventArgs e)
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at OutSystems.HubEdition.WebWidgets.Span.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control....ets.Container.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at OutSystems.HubEdition.WebWidgets.OSDataGridTableCell.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at OutSystems.HubEdition.WebWidgets.OSDataGrid.InsertItem(Int32 dataItemIndex, Object dataItem)
   at OutSystems.HubEdition.WebWidgets.OSPageViewState.AjaxRefresh(Control c, Int32 rowIndex, String animationName, String listOperation, Boolean isTableRecord, Object dataItem, StoreViewStateDelegate storeViewStateDelegate)

Hi thiha,

The error is not directly caused by the ListInsert itself, but what happens afterwards. If I had to guess, the List you are ListInserting an item to is bound to a Widget on the Screen, and inside your Screen logic, there's a GetSkill() in an Expression. GetXxx() Entity Actions will throw an Exception when they can't find the data, and the "key 0" indicates you tried to retrieve a Skill with NullIdentifier(), which means the item you inserted in the List doesn't have a valid value (viz. NullIdentifier()) as SkillId.

Kilian Hekhuis wrote:

Hi thiha,

The error is not directly caused by the ListInsert itself, but what happens afterwards. If I had to guess, the List you are ListInserting an item to is bound to a Widget on the Screen, and inside your Screen logic, there's a GetSkill() in an Expression. GetXxx() Entity Actions will throw an Exception when they can't find the data, and the "key 0" indicates you tried to retrieve a Skill with NullIdentifier(), which means the item you inserted in the List doesn't have a valid value (viz. NullIdentifier()) as SkillId.

Hi Thank you for speedy reply. I am adding new record of Staff table which has Skill ID FK column and FK column has IsMandatory =No. I have tried setting the special list of Skill ID combo box with 0 value an "Select one" option.  But the error still occurs. So how can i add new record and display "Select one" at Skill ID dropdown? 


Hi thiha,

If Skill is not mandatory, you should put some code around the GetSkill() in the Expression, testing for NullIdentifier(), and in that case not calling GetSkill().

GetSkillList is just a simple query from Skill entity. it is directly bound to Combo box. Please advise or share sample code how  i can add expression to it.


 

Hi thiha,

What I tried to tell you is that the error you experience is not caused by a query (Aggregates and SQL never cause exceptions like this), but by this (top line from the stack dump):

at ssHRManagement.ExtendedActions.GetSkill(HeContext heContext, Int32 inParamId, RCSkillRecord& outParamRecord)

Which means that somewhere, most likely in a Table Records on the Screen, there's already an Expression that calls GetSkill(), and which goes wrong (because there's not a valid Id).

If you don't know where it is, go to the Data Tab in Service Studio, locate the Skill Entity, Expand it in the tree, select the GetSkill Action and press F12 (or right-click and select "Find Usages").

Hi Hekhuis, the table records on screen for staff list has Staff Id combo box column which is bound to GetSkillList query as per my previous message. When adding a new row for staff, the table record triggers the combo box trying to find Skill Id 0 from GetSkillList. In this case, can we don't throw the error and use the value 0 from special list of combo box? Or Is there any other way to set empty value of combo box?

Hi thiha (or is aung your first name?),

Did you search for GetSkill like I asked? Could you find it? Anyway, could you share an eSpace? It's difficult to find the problem this way.

Hi Kilian, you can call me Thiha. I dont' find the exact name "GetSkill" in the eSpace and references. As I mentioned, in Preparation action of the screen, I have GetSkillList query which get all the records of Skill entity. And use it (GetSkillList) to bind the combo box. 

Right now, I did work around (actually not fix) to set valid skill id before inserting new staff row into Record list. This is just to prevent the error but what i want is that when adding new row, the screen should choose the 0 value from Special list of skill combo box .

Unfortunately, I couldn't share the eSpace due to company policy. Sorry about that. 

As per below screenshot, combo box is inside the table (the table is boubd to the record list). When clicking "Add New" button, it triggers Add action. Inside Add action, it add new record to record list and refresh the table container. 

Solution

Hi Thiha,

I think the problem might be in the "Competency Type" column, the Expression that displays "Skill Type". Can you show what the Expression says?

Solution

Hi Kilian,  the expression at "Skill Type" has the below statement. But the statement looks wrong. 

SyntaxEditor Code Snippet

If(CompTypeList.Skill.Id=NullIdentifier(),GetSkill(StaffTable1.List.Current.Staff.SkillsetId).Skill.Type,GetSkill(StaffTable1.List.Current.Staff.SkillsetId).Skill.Type)

  

It should be like this, right?

SyntaxEditor Code Snippet

If(StaffTable1.List.Current.Staff.SkillsetId=IntegerToEntityRefInteger(0),"",GetSkill(StaffTable1.List.Current.Staff.SkillsetId).Skill.Type)

aung thiha wrote:

Hi Kilian,  the expression at "Skill Type" has the below statement. But the statement looks wrong. 

SyntaxEditor Code Snippet

If(CompTypeList.Skill.Id=NullIdentifier(),GetSkill(StaffTable1.List.Current.Staff.SkillsetId).Skill.Type,GetSkill(StaffTable1.List.Current.Staff.SkillsetId).Skill.Type)

  

It should be like this, right?

SyntaxEditor Code Snippet

If(StaffTable1.List.Current.Staff.SkillsetId=IntegerToEntityRefInteger(0),"",GetSkill(StaffTable1.List.Current.Staff.SkillsetId).Skill.Type)

After I have changed the expression, it works now. Thank you very much for your help.


Hi Thiha,

Indeed, the GetSkill() in the Expression is what caused your error: if StaffTable1.List.Current.Staff.SkillsetId is NullIdentifier(), the exception is triggered.