Miscellaneous Scripts
-
How to Return a Multi-value String Array Using a Single Property
-
How to Get a Dataset Industry Field and Return it as a MULTI
-
How to Resolve SSL Certification Issues on Web Requests in Scripts
VB.NET Code Sample
See the following common code sample for the VB.NET scripts:
dim origFile as string = HOST.GetStringValue("document")
try
if not string.IsNullOrEmpty( origFile ) Then
dim ext as string= origFile.substring(origFile.LastIndexOf(".") + 1)
dim newFilePath as string = HOST.GetTempFilePath(ext)
File.Copy(origFile,newFilePath)
File.SetLastWriteTime(newFilePath, Date.now)
return newFilePath
else
return "NOFILE"
end if
catch x as exception
return origfile
end try
How to Return a Multi-value String Array Using a Single Property
Usage: Single property
Description: Split a string and create a new multi-value list of all of the name parts so that this list can be searched.
ESC_NAME is the original name metadata
ESC_NAME_SEARCH field is the custom MULTI result, script here
Property: ESC_NAME Type: STRING Value: Conrady, Mike
Property: ESC_NAME_SEARCH Type: STRING Value: ARRAY (4):Con,Conr,Conra,Conrad
' get the full name (formatted last,first) from the metadata:
DIM Fullname as String = HOST.GetStringValue("name")
HOST.WriteTrace("PARTIAL NAME SEARCH FIELD Full Name In: "+ FullName)
'split it to get just the last name
DIM nameparts() as String= Fullname.Split(",")
DIM lastname as String = nameparts(0)
HOST.WriteTrace(" Last Name : " + lastname)
'If the last name is less than four characters, just return it.
if lastname.length<4
return lastname
end if
'otherwise, get a substring of the first three characters, then the first 4, etc, and add them to an array.
DIM pos as integer = 3
DIM output as new arraylist()
DIM part as String
for pos = 3 to lastname.length-1
part = lastname.substring(0,pos)
output.add(part)
HOST.WriteTrace(" Part: "+ part)
next
return output.toarray(gettype(string))
How to Get a Dataset Industry Field and Return it as a MULTI
Usage: Single column
Description: Get a single column from the 2nd SQL selection and return all of the values as a MULTI
-
For datasets and multiple SQL commands:
-
The first
SELECT
in theGetItem()
SQL isdataset(0).
-
If there is a second
SELECT
in theGetItem()
SQL, this is a data
dim ds as dataset = host.getdataset()
dim idx as integer = 1
' The count below is number of rows brought back from SQL.
dim ct as integer = ds.tables(idx).rows.count
dim i as integer = 0
DIM output as new arraylist()
for i = 0 to ct-1
dim industry as string = ds.tables(idx).rows(i)("INDUSTRY")
output.add(industry)
next
return output.toarray(gettype(string))
How to Extract the Extension From a Path
Usage: Extension column
Description: Assumes that the documentfilename
column has the file extension.
dim ext as string = HOST.GetStringValue("documentfilename")
return ext.substring(ext.lastindexof(".") + 1)
How to Get a Complex Path Definition
Usage: Unstructured data column
Description:
-
Takes advantage of an additional table of data that exists because the item query has two SQL statements.
-
This is from a worksite database where the path is created by combining a file name with the path that goes with a specific server.
Dim servName as String
Dim docLoc as String
docLoc = HOST.GetStringValue ("docloc")
servName = docLoc .SubString(0,docLoc .indexOf(":")).Trim()
for i as Integer = 0 to HOST.GetDataSet().Tables(1).Rows.Count -1
if HOST.GetDataSet().Tables(1).Rows(i)("DocServer").ToString().Trim() = servName then
return docLoc.Replace(servName & ":",HOST.GetDataSet().Tables(1).Rows(i)("Location").ToString().Trim())
end if
next
return "Failed"
How to Get Direct Dataset Access
Usage: Title column, metadata - text
Description: If there is more than one SQL statement or more than one row, this statement combines the data from all of the rows into one string.
dim ds as Dataset
ds = HOST.GetDataSet()
dim i as integer = 0
dim fieldName as string = "myFieldName"dim dsindex as integer = 1
dim sb as new StringBuilder()
dim al as new arraylist
for i = 0 to ds.tables(dsindex).rows.count -1
if HOST.MyToString(ds.tables(dsindex).rows(i)(fieldName)).trim() <> "" then
sb.append(ds.tables(dsindex).rows(i)(fieldName).tostring().trim() & ",")
al.add(ds.tables(dsindex).rows(i)(fieldName).tostring().trim())
end if
next
return al.toarray(gettype(string)) 'note: multi-array return
' return sb.tostring().trim(",") ' use this to return big string instead
How to Perform a Simple, Conditional String Replacement
Usage: Unstructured data column, author column, title column, metadata - text
Description: If one value is empty, use another value.
If HOST.GetStringValue("ResourceName") = "" then
return HOST.GetStringValue("ResourceName2")
else
return HOST.GetStringValue("ResourceName")
end if
How to Extract Values from XML-based Data
Usage: Unstructured data column, extension column, author column, title column, metadata - text
Description: A starting script that is used to extract data from a node list
dim attName as string = ""dim fieldName as string = "lit_judge_primary"dim isMulti as boolean = true
dim dupCheck as new hashtable
dim xStr as string = HOST.GetStringValue(fieldName).trim()
if xStr = "" then return ""dim xmlDoc as new XmlDocument()
xmlDoc.LoadXml("<xmlwrap>" + xStr + "</xmlwrap>")
if isMulti then
dim xnodes as xmlnodelist = xmldoc.documentelement.childnodes
dim al as new arraylist()
for i as integer = 0 to xnodes.count -1
if (not dupCheck.containsKey(xnodes(I).innertext)) then
al.add(xnodes(I).innertext)
dupCheck(xnodes(I).innertext) = true
end if
next
return al.toarray(gettype(string))
end if
if (attName <> "") then
if (xmldoc.documentelement.childnodes(0).Attributes.GetNamedItem(attName) is nothing) then return "" return xmldoc.documentelement.childnodes(0).Attributes.GetNamedItem(attName).Value
else
return xmldoc.documentelement.childnodes(0).innertext
end if
How to Resolve SSL Certification Issues on Web Requests in Scripts
Usage: Unstructured data column, metadata - text
Description:
-
There are built-in
HOST.
methods for executing URLs and you can also use the.net
methods. -
But if there are certificate issues you might need to override the SSL handling by adding this code to the beginning of your script.
static lockObj as new object()
static callbackSet as boolean = false
synclock lockObj
if not callbackset then
System.Net.ServicePointManager.ServerCertificateValidationCallback = Nothing
System.Net.ServicePointManager.DefaultConnectionLimit = 200
callbackset = true
end if
end synclock
How to Filter E-mails
Usage: Exchange filter script
Description: Filters email by from
, to
, or subject
if (HOST.GetStringValue("SPW_SUBJECT").contains("SPAM:")) then return false
if (HOST.GetStringValue("SPW_FROM").contains("@badmail.com")) then return false
HOST.WriteTrace(HOST.GetStringValue("SPW_TO"))
' to see what values are 'the SPW_TO can contain multiple values from both TO and CC fields seperated by semicolons
if (HOST.GetStringValue("SPW_TO").contains("@hotmail.com")) then return false
return true ' important last step