Save ListItem
- Last UpdatedJun 10, 2024
- 1 minute read
Save a ListItem using list API.
The list API makes use of the following DLL references, namespaces, classes, and methods.
|
DLL Reference |
Namespace |
|---|---|
|
|
|
Class |
|---|
|
|
Methods |
|---|
|
Scenario 1
For the Employee list mapped to an Emp table with the fields such as Title, Name, City, State, Pincode, and Age, save the ListItem by running the following code.
using System;
using Workflow.NET;
using Workflow.NET.Engine;
using Skelta.Forms.Core.Controls;
using Skelta.Repository.List;
public class WorkflowScript0144412702584f2a8852a95a0a727737
{
public string Run(int ExecutionId, int ExecutionDetailsId, Workflow.NET.Engine.Context ctx, Workflow.NET.Action action, string inlink)
{
string applicationname = ctx.ApplicationName;
string listname = "Employee";
ListDefinition lstdef = new ListDefinition(new Skelta.Core.ApplicationObject(applicationname), listname);
Skelta.Repository.List.ListItem listItem = new Skelta.Repository.List.ListItem(lstdef);
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("Title"))).Value = "T3";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("Name"))).Value = "A3";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("City"))).Value = "C3";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("State"))).Value = "S3";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("PinCode"))).Value = "P3";
((ListIntDataItem)(listItem.ListForm.Records[0].FindControlByName("Age"))).Value = "20";
listItem.Save();
return "saved";
}
}
Scenario 2
If we add a new column to the Emp Table say Department, then we need to call the ClearTableNameKeyFromTableCollection API before calling the listitem.save().
Skelta.Core.DS.SingleTableObject.ClearTableNameKeyFromTableCollection(ctx.DataHandler.DataSourceType, applicationname, "EmpTable");
using System;
using Workflow.NET;
using Workflow.NET.Engine;
using Skelta.Forms.Core.Controls;
using Skelta.Repository.List;
public class WorkflowScript0144412702584f2a8852a95a0a727737
{
public string Run(int ExecutionId, int ExecutionDetailsId, Workflow.NET.Engine.Context ctx, Workflow.NET.Action action, string inlink)
{
string applicationname = ctx.ApplicationName;
string listname = "Employee";
Skelta.Core.DS.SingleTableObject.ClearTableNameKeyFromTableCollection(ctx.DataHandler.DataSourceType, applicationname, "Emp");
ListDefinition lstdef = new ListDefinition(new Skelta.Core.ApplicationObject(applicationname), listname);
Skelta.Repository.List.ListItem listItem = new Skelta.Repository.List.ListItem(lstdef);
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("Title"))).Value = "T3";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("Name"))).Value = "A3";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("City"))).Value = "C3";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("State"))).Value = "S3";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("PinCode"))).Value = "P3";
((ListIntDataItem)(listItem.ListForm.Records[0].FindControlByName("Age"))).Value = "20";
((ListTextDataItem)(listItem.ListForm.Records[0].FindControlByName("Department "))).Value = "R&D";
listItem.Save();
return "saved";
}
}