Siebel Tools > A simple delete example with eScript in Siebel Tools
A simple delete example with eScript in Siebel Tools
We will delete activities.
The user will send an Activity UId and we will delete all rows that match this UID.
First check out Project 'Activity'. Open Business Component Action -> Click on 'Edit Server Scripts' and go to section
'BusComp_PreInvokeMethod'
here add these lines to function BusComp_PreInvokeMethod (MethodName).
function BusComp_PreInvokeMethod (MethodName)
{
case "DeleteActivity": this.SearchActivity(this.GetFieldValue("Id"));
return (CancelOperation);
}
The first line will accept the Activity UID to delete . The second line 'return (CancelOperation);' is recommended.
Then create a function called DeleteActivity.
You need to click on (general) and type 'function DeleteActivity(Inputs, Outputs)'
Siebel Tools will automatically create a function section.
Then write this code in the function:
function DeleteActivity(Inputs, Outputs) {
//Declare variables
var bo : BusObject;
var bc : BusComp;
var UID : String ;
var n : Number;
try
{
n = 0;
bo = TheApplication().GetBusObject('Activity');
bc = bo.GetBusComp('Activity');
UID = Inputs.GetProperty("rows"); //Get input parameters through GetProperty() function
with (bc)
{
ClearToQuery(); // Clear cache of datasets in cursor
SetViewMode(AllView); //You can work with data from all organisations
InvokeMethod("SetAdminMode", "TRUE"); //Allow to edit and delete data on Database level
ActivateField("Activity UID"); /* Activate the fields to be used. We will delete based on Activity UID */
SetSearchSpec("Id",UID); /* SetSearchSpec sets the query , equivalent to where clause in an SQL */
ExecuteQuery(); // Run the query
var recordExists = FirstRecord(); // Set resulting dataset pointer to first record
while (recordExists) // loop until data exists in resultset
{
DeleteRecord();
recordExists = FirstRecord(); // Reset the pointer to point at first record in resultset
}
Outputs.SetProperty("RecordCount", n); //To check the number of rows processed
}
return(CancelOperation); }
catch(e)
{
TheApplication().RaiseErrorText("NcPrintService " + e.toString());
} finally
{
bc = null;
bo = null;
}
}
Please note that the html converter that I am using is changing the code quite a lot. Please check if there are syntax errors and correct them. There may be a missing bracket for example.
|