Content Management and Capture

 View Only

 Converting from VBScript to C# custom actions

Danny Mann's profile image
Danny Mann posted 04/27/26 04:10 PM

Good afternoon. We are running Datacap 9.1.9 iFix 006.  We have a lot of old VBScript custom actions that we have accumulated over the years.  Recently we have started the process of writing any new custom actions in C#.  We are using the IBM-Datacap-DDK-9.1.9-ifix-006.zip downloaded from github.  I have written several custom actions inside the sample CustomActions class with no issues.  However now I need to do some simple things that I previously did in VBScript but can't seem to figure out how to do it in C# custom action.  In VBScript custom action we could do this:

Set oBatch = CurrentObj.Parent()
Set oDoc = CurrentObj
Set oPage = oDoc.GetChild(0) 


oDoc.Variable("P8_DocumentType") = "TestDocType"
oPage.Variable("Identifier") = "testIdentifer"

I just need to be able to do the exact same thing in C# custom action.  

Any help is greatly appreciated.

Shaun McDowall's profile image
Shaun McDowall

Hi Danny,

Here's some sample code that gets the level in the hierarchy (you may have seen this in the DDK)

// An example of how to determine the level of the current DCO object.
if (CurrentDCO.ObjectType() == Level.Batch)
{
	WriteLog("Batch Level");
}
else if (CurrentDCO.ObjectType() == Level.Document)
{
	WriteLog("Document Level");
}
else if (CurrentDCO.ObjectType() == Level.Page)
{
	WriteLog("Page Level");
	string imageName = CurrentDCO.ImageName; // We are at the page level, here is how to obtain the image name.
	WriteLog("Image name: " + imageName);
}
else if (CurrentDCO.ObjectType() == Level.Field)
{
	WriteLog("Field Level");
}

Here is some other code that sets a variable:

 // Here is an example of setting a variable in the DCO.  If the variable does not exist, it will be created.

bool result = localSmartObj.DCONavSetValue("@B.MyVariable", smartP1);
if (result)
{
	WriteLog("MyVariable was set in the DCO at the batch level.");
}
else
{
	WriteLog("MyVariable was not set in the DCO");
}

I haven't tested this, but here goes:

// Get current objects
var oDoc = CurrentDCO;                  // Current document
var oBatch = oDoc.Parent();               // Parent batch
var oPage = oDoc.GetChild(0);           // First page

// Set variables
oDoc.set_Variable("P8_DocumentType", "TestDocType");
oPage.set_Variable("Identifier", "testIdentifier");

I hope this helps!

Shaun

Danny Mann's profile image
Danny Mann

All of the below code works perfectly and is just what I needed.  Thank you very much for taking time to give this reply:
// Get current objects
var oDoc = CurrentDCO; // Current document
var oBatch = oDoc.Parent(); // Parent batch
var oPage = oDoc.GetChild(0); // First page 
// Set variables
oDoc.set_Variable("P8_DocumentType", "TestDocType"); 
string workflowTest = oBatch.get_Variable("@B.Workflow");
smart.DCONavSetValue("@B.P8_NotificationEmail", "someEmail");

Shaun McDowall's profile image
Shaun McDowall

Hi Danny,

No problem - glad it worked!

Shaun