Friday, June 5, 2015

Datacap C# Smart Parameter parsing using MetaWord

I keep having to look up how to get a smart parameter in Datacap using both C# and VBScript. Figure it's time to leave myself a breadcrumb.

Here is the sample in C#, it comes directly from the vScanSample where I always look for it.
        public bool myact_set_folder(string sPath)      // set the folder to search for files
        {
            dcSmart.SmartNav localSmartObj = null;
            try
            {
                localSmartObj = new dcSmart.SmartNav(this);
                //If the parameter is a smart parameter, look up the actual path (returns the original path if it was not a smart parameter)
                mFolderPath = localSmartObj.MetaWord(sPath);
                RRLog.Write("Image source folder set to: " + mFolderPath);
            }
            catch (Exception ex)
            {
                RRLog.Write("myact_set_folder error: " + ex.ToString()); 
                return false;
            }
            finally
            {
                localSmartObj = null;
            }

            return true;
        }


Here is the VBScript Datacap custom action version to parse the smart parameter. This comes directly from one of my own custom actions I use for doing text searching.

   'Get the smart parameter for the FinderString
    sTmp = MetaWord(FinderString)
    If (sTmp = "") Then 'Field Value
        Set oChild = CurrentObj.FindChild(Right((FinderString), Len((FinderString))-1))
        If Not(oChild Is Nothing) Then
           WriteLog("Hostname from field")
           sTmp = oChild.Text
    Set oChild = Nothing
        End If
    End If
    ValueToSearch = sTmp
    WriteLog("ValueToSearch = " & ValueToSearch)

Hope I remember that I left myself this note here

No comments: