Help with Scripted Business Objects
Hello Everyone,
I'm just trying to get started on Scripted Business Objects. The last couple of days I have been reading the Designer Manual and going through the Samples of scripted Bo's provided with the installation.
After all of this I'm starting to put together my script. It displays data corectly on my grid, but no matter what I can't make it editable. There should be something wrong with my script or I'm not implementing correctly some of the functions.
I hope someone can help me figure it out, or if somebody can provide an example it wold be very helpful.
Basically what I want to acomplish is to have an editable grid, that displays data from a simple SQL query (select from 2+ tables), and to update back the corresponding tables depending on the data modified.
Here is my script:
#region Using Statement
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Metastorm.Ide.Extensibility;
using Metastorm.Runtime.Core;
using Metastorm.Runtime.Types;
using System.ComponentModel;
using Metastorm.Runtime.Contracts.Mbo;
using Metastorm.Runtime.Core.Mbo;
using System.Linq;
#endregion Using Statement
namespace Metastorm.Runtime.Models.AdministracionDatosMaestros
{
public abstract class ScriptedBO : IDataSetAccess, IEditableAccess
{
private DataSet data = null;
private MboConnection connection = null;
private MboConnectionInfo connectioninfo = null;
public ScriptedBO()
{
}
public ScriptedBO(MboConnection connection) : this()
{
this.connection = connection;
}
public ScriptedBO(MboConnectionInfo connectionInfo) : this()
{
if (connectionInfo != null)
{
if (connectionInfo.MetastormDefault){
this.connection = new EngineMboConnection();
this.connectioninfo = connectionInfo;
}
else{
this.connection = new MboConnection(connectionInfo);
this.connectioninfo = connectionInfo;
}
}
CacheHelper.LoadFromCache += LoadDataFromCache;
CacheHelper.SaveToCache += SaveDataToCache;
LoadDataFromCache(this, EventArgs.Empty);
}
#region Parameters
// public abstract Metastorm.Runtime.Types.Text YearMonth { get; }
// public abstract Metastorm.Runtime.Types.Text Usuario { get; }
// public abstract Metastorm.Runtime.Types.Text Planta { get; }
// public abstract Metastorm.Runtime.Types.Text Modulo { get; }
#endregion
#region IDataSetAccess Members
public System.Data.DataSet Read()
{
if (data == null)
{
data = Mstm.SelectSql(this.connectioninfo, "SELECT Cf_Active_Status_id, Cf_WorkFlow_Status_id, Cf_Source_System_id,Cf_Entity_id,Cf_Attribute_id,Source_Attibute_id,Source_Attibute_DescM,Central_Attribute_Id FROM [DS4_STG_SBX].[dbo].[Cf_LookUp]", null).GetDataSet();
data.AcceptChanges();
}
return data;
}
public void Write(System.Data.DataSet dataSet)
{
if (dataSet.HasChanges())
data.Merge(dataSet.GetChanges());
}
#endregion
#region IEditableAccess Members
public virtual bool ReadOnly
{
get { return false; }
}
public void Commit()
{
if (data.HasChanges())
{
DataSet cambios = null;
cambios=data.GetChanges();
this.connection.Update(cambios);
}
}
#endregion
#region Variables
public virtual Metastorm.Runtime.Types.Text Cf_Active_Status_id {
get { return GetField("Cf_Active_Status_id"); }
set { SetField("Cf_Active_Status_id", value); }
}
public virtual Metastorm.Runtime.Types.Text Cf_WorkFlow_Status_id {
get { return GetField("Cf_WorkFlow_Status_id"); }
set { SetField("Cf_WorkFlow_Status_id", value); }
}
public virtual Metastorm.Runtime.Types.Text Cf_Source_System_id {
get { return GetField("Cf_Source_System_id"); }
set { SetField("Cf_Source_System_id", value); }
}
public virtual Metastorm.Runtime.Types.Text Cf_Entity_id {
get { return GetField("Cf_Entity_id"); }
set { SetField("Cf_Entity_id", value); }
}
public virtual Metastorm.Runtime.Types.Text Cf_Attribute_id {
get { return GetField("Cf_Attribute_id"); }
set { SetField("Cf_Attribute_id", value); }
}
public virtual Metastorm.Runtime.Types.Text Source_Attibute_id {
get { return GetField("Source_Attibute_id"); }
set { SetField("Source_Attibute_id", value); }
}
public virtual Metastorm.Runtime.Types.Text Source_Attibute_DescM {
get { return GetField("Source_Attibute_DescM"); }
set { SetField("Source_Attibute_DescM", value); }
}
public virtual Metastorm.Runtime.Types.Text Central_Attribute_Id {
get { return GetField("Central_Attribute_Id"); }
set { SetField("Central_Attribute_Id", value); }
}
#endregion
#region ISupportRefill Members
public virtual bool AlwaysRefresh
{
get { return false; }
}
#endregion
#region Helper methods
private T GetField(string fieldName)
{
if (data == null) this.Read();
if (data != null && data.Tables.Count > 0 && data.Tables[0].Rows.Count > 0)
return (T)data.Tables[0].Rows[0][fieldName];
else
return default(T);
}
private void SetField(string fieldName, T value)
{
if (data != null && data.Tables.Count > 0 && data.Tables[0].Rows.Count > 0)
data.Tables[0].Rows[0][fieldName] = value;
}
#endregion
#region Caching events
private void SaveDataToCache(object sender, EventArgs e)
{
if (data != null)
CacheHelper.GetCachedMboState(this).Data = data;
}
private void LoadDataFromCache(object sender, EventArgs e)
{
data = CacheHelper.GetCachedMboState(this).Data;
}
#endregion
}
}
Comments
-
Hi Fernando
I think you need to set a primary key for your DataTable in the Read method, like this.
data.Tables[0].PrimaryKey = new DataColumn[] {data.Tables[0].Columns["Id"]};
Thanks
iain
0 -
Hi,
Kindly need help with a small examplke of scripted BO that writes data back to da database.
It would be really helpfull
Thanks !!
0
Categories
- All Categories
- 123 Developer Announcements
- 54 Articles
- 152 General Questions
- 148 Thrust Services
- 57 Developer Hackathon
- 37 Thrust Studio
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 918 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 32 eDOCS
- 190 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 9 XM Fax
- Follow Categories