Convert vbscript into rapid integration flowlanguage - vbscript

I'm using Pervasive 9.2 and would like to somehow convert the vbscript into pervasives RIFL language. I want to execute the code during a Process where the f(x) component is executed to run the code. As far as the Path to the xml data, I'll be using a Macro defining where the source data is and another to save the file as well.
Here is the vbscript code below:
Set xml = CreateObject("Microsoft.XMLDOM")
xml.async = False
count_var = 1
If xml.Load("c:\folder1\test.xml") Then
For Each accounts In xml.SelectNodes("//Accounts")
For Each account In Accounts.SelectNodes("./Account")
If count_var > 1 Then
Set accountEnum = xml.createNode(1, "Account" & count_var, "")
For Each child In Account.childNodes
accountEnum.appendChild(child.cloneNode(TRUE))
Next
Accounts.replaceChild accountEnum, Account
xml.save("c:\folder1\test.xml")
else
Set accountEnum = xml.createNode(1, "Account" & count_var, "")
For Each child In Account.childNodes
accountEnum.appendChild(child.cloneNode(TRUE))
Next
Accounts.replaceChild accountEnum, Account
xml.save("c:\folder1\test.xml")
End If
count_var = count_var + 1
Next
count_var = 1
Next
End If
Set node = Nothing
Set xml = Nothing

ParseXMLFile(filepath)
documentation here
http://docs.pervasive.com/products/integration/di/rifl/wwhelp/wwhimpl/common/html/wwhelp.htm#href=ParseXMLFile_Function.html&single=true
this will return a DOMDocument Object Type
documentation here
http://docs.pervasive.com/products/integration/di/rifl/wwhelp/wwhimpl/common/html/wwhelp.htm#href=DOMDocument_Object_Type.html&single=true
hope this helps

Related

How to check if two or more conditions are met vs only one of them is true?

I'm using the following script with a software which reads a CheckBox using OMR and outputs the data to an XML file.
Is there a way I can change it to say if more than one box has been checked, the data output should be the first checked box in the list?
Hope this makes sense.
Any help would be appreciated.
Dim installer
q_a1= Metadata.Values("OMR_FRED_P2")
q_a2= Metadata.Values("OMR_JON_P2")
q_a3= Metadata.Values("OMR_MATT_P2")
q_a4= Metadata.Values("OMR_STEVE_P2")
If q_a1 = "Filled" Then
installer = "Fred"
End If
If q_a2 = "Filled" then
installer = "Jon"
End If
If q_a3 = "Filled" then
installer = "Matt"
End If
If q_a4 = "Filled" then
installer = "Steve"
End If
call Metadata.SetValues("CompleteBy",installer)
You could do something like this:
Dim a1Checked, a2Checked, a3Checked, a4Checked
Dim numberOfChecked
a1Checked = (q_a1 = "Filled")
a2Checked = (q_a2 = "Filled")
a3Checked = (q_a3 = "Filled")
a4Checked = (q_a4 = "Filled")
numberOfChecked = Abs(a1Checked + a2Checked + a3Checked + a4Checked)
If a1Checked Or numberOfChecked > 1 Then
installer = "Fred"
ElseIf a2Checked Then
installer = "Jon"
ElseIf a3Checked Then
installer = "Matt"
ElseIf a4Checked Then
installer = "Steve"
Else
' Decide what you want to do if none is checked.
End If
Call Metadata.SetValues("CompleteBy", installer)
In VBScript, the numeric value of a "boolean true" value is -1 and of the false value is 0.
The above code simply adds the values together. If two conditions are met, the total would be -2, then we use the Abs function to get the abstract value (i.e., returning 2 instead of -2). After that, you can easily check if two or more conditions are met by using numberofChecked > 1.

Access 2010 - Run-time error 3022

I'm trying to add records to an exisiting table called "Topics" (section as of "For Each SelectedTopic In SelectedTopicsCtl.ItemsSelected" in the code below).
When executing the code i always get "Run-time error '3022': The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. So it goes wrong at the creation of the Autonumber in the field "ID" (= the only field that is indexed - no duplicates).
When debugging, line "TopicRecord.Update" in the code below is highlighted.
I have read several posts on this topic on this forum and on other forums but still cannot get this to work - i must be overlooking something....
Private Sub Copy_Click()
Dim JournalEntrySourceRecord, JournalEntryDestinationRecord, TopicRecord As Recordset
Dim JournalEntryToCopyFromCtl, JournalEntryToCopyToCtl, JournalEntryDateCreatedCtl, SelectedTopicsCtl As Control
Dim Counter, intI As Integer
Dim SelectedTopic, varItm As Variant
Set JournalEntryToCopyFromCtl = Forms![Copy Journal Entry]!JournalEntryToCopyFrom
Set JournalEntryToCopyToCtl = Forms![Copy Journal Entry]!JournalEntryToCopyTo
Set JournalEntryDateCreatedCtl = Forms![Copy Journal Entry]!JournalEntryDateCreated
Set JournalEntrySourceRecord = CurrentDb.OpenRecordset("Select * from JournalEntries where ID=" & JournalEntryToCopyFromCtl.Value)
Set JournalEntryDestinationRecord = CurrentDb.OpenRecordset("Select * from JournalEntries where ID=" & JournalEntryToCopyToCtl.Value)
Set SelectedTopicsCtl = Forms![Copy Journal Entry]!TopicsToCopy
Set TopicRecord = CurrentDb.OpenRecordset("Topics", dbOpenDynaset, dbSeeChanges)
With JournalEntryDestinationRecord
.Edit
.Fields("InitiativeID") = JournalEntrySourceRecord.Fields("InitiativeID")
.Fields("DateCreated") = JournalEntryDateCreatedCtl.Value
.Fields("Comment") = JournalEntrySourceRecord.Fields("Comment")
.Fields("Active") = "True"
.Fields("InternalOnly") = JournalEntrySourceRecord.Fields("InternalOnly")
.Fields("Confidential") = JournalEntrySourceRecord.Fields("Confidential")
.Update
.Close
End With
JournalEntrySourceRecord.Close
Set JournalEntrySourceRecord = Nothing
Set JournalEntryDestinationRecord = Nothing
For Each SelectedTopic In SelectedTopicsCtl.ItemsSelected
TopicRecord.AddNew
For Counter = 3 To SelectedTopicsCtl.ColumnCount - 1
TopicRecord.Fields(Counter) = SelectedTopicsCtl.Column(Counter, SelectedTopic)
Next Counter
TopicRecord.Fields("JournalEntryID") = JournalEntryToCopyToCtl.Value
TopicRecord.Fields("DateCreated") = JournalEntryDateCreatedCtl.Value
TopicRecord.Update
Next SelectedTopic
TopicRecord.Close
Set TopicRecord = Nothing
End Sub
First, your Dims won't work as you expect. Use:
Dim JournalEntrySourceRecord As Recordset
Dim JournalEntryDestinationRecord As Recordset
Dim TopicRecord As Recordset
Second, it looks like you get your ID included here:
TopicRecord.Fields(Counter)
or Topic is a query that includes it somehow. Try to specify the fields specifically and/or debug like this:
For Counter = 3 To SelectedTopicsCtl.ColumnCount - 1
TopicRecord.Fields(Counter).Value = SelectedTopicsCtl.Column(Counter, SelectedTopic)
Debug.Print Counter, TopicRecord.Fields(Counter).Name
Next Counter

Reduced performance when creating object in classic asp

Trying to measure a website performance I created a simple logging sub to see what parts are slow during the execution of a classic asp page.
sub log(logText)
dim fs, f
set fs = Server.CreateObject("Scripting.FileSystemObject")
set f = fs.OpenTextFile("log.txt", 8, true)
f.WriteLine(now() & " - " & logText)
f.Close
set f = Nothing
set fs = Nothing
end sub
log "Loading client countries"
set myR = Server.CreateObject("ADODB.RecordSet")
myR.ActiveConnection = aConnection
myR.CursorLocation=2
myR.CursorType=3
myR.LockType=2
myR.Source = "SELECT * FROM CC ORDER BY ccName ASC"
log "Opening db connection"
myR.open()
log "Opened db connection"
Here are the results (only showing the time part):
...
11:13:01 - Loading client countries
11:13:06 - Opening db connection
11:13:06 - Opened db connection
...
Creating the ADODBRecordSet and setting a few properties takes about 5 seconds. This does not always happen, sometimes the code is executed fast, but usually when I reload the page
after a few minutes the loading times are more or less the same as the example's. Could this really be a server/resources issue or should I consider rewriting the code? (My best option would be to write this in C#, but I have to study this code first before moving forward anyway).
Update: I added more code after receiving 1st comment to present a few more code. Explanation: The code creates a combobox (selection menu) with the retrieved countries (it continues where the previous piece of code stopped).
if not myR.eof then
clientCountries = myR.getrows
send("<option value='0'>Select country</option>")
log "Creating combobox options"
for i = 0 to ubound(clientCountries, 2)
if cstr(session("clientCountry")) <> "" then
if cstr(clientCountries(1, i)) = cstr(session("clientCountry")) then
isSelected = "selected" else isSelected = ""
end if
end if
if cstr(session("clientCountry")) = "" then
if cstr(clientCountries(1, i)) = "23" then
isSelected = "selected"
else
isSelected = ""
end if
end if
optionString = ""
optionString = clientCountries(2, i)
send("<option value='" & clientCountries(1, i) & "' " & isSelected & ">" & convertToProperCase(optionString) & "</option>")
next
log "Created combobox options"
end if
myR.Close
myR.ActiveConnection.close
myR.ActiveConnection = nothing
set myR = nothing
log "Loaded client countries"
The next two log entries are as follows:
11:13:06 - Creating combobox options
11:13:06 - Created combobox options
...
So far, the SELECT query as the rest of the page (2 or 3 queries more) is executed within the next second more or less. The only part slowing the page down is what you can see in the first part of the log. I'm not sure if I can profile the SQLServer, because I only have cPanel access. This is the only way I know of, unless there's something else I could have a look at.
First, Check your connection string, I've experienced slower times with certain providers. The best provider I've found for classic asp is sqloledb
Second, I would close my SQL object before I did the For statement on the GetRows() array. You don't want to keep that open if you don't need to.
Third, I'd use stored procedures. You'll get a performance improvement by saving on compile time.
Fourth, I would avoid doing a SELECT * statement at all cost, instead I would return ONLY the columns I need. (Your code looks like it only needs 2 columns)
Fifth, I would build indexes on the tables taking longer than expected.
If this doesn't resolve the issue, I would consider other languages/solutions. Not sure what the dataset looks like, so can't say if a flat-file database should be considered or not.
Also, try this for a recordset instead and see what happens:
Set myR = Server.CreateObject("Adodb.Recordset")
myR.Open "SELECT * FROM CC ORDER BY ccName ASC", aConnection
If myR.RecordCount > 0 Then clientCountries = myR.GetRows()
myR.Close
Set myR = Nothing
If IsArray(myR) Then
For ....

SAP BAPI get all Functional Locations

I have been a longtime lurker of stackoverflow and have now decided to join. I am trying to pull a list of every Functional Location out of SAP using BAPI. When I run this code it returns with an empty table. I dont have very much experiance with BAPI and I am trying to teach myself. Can someone please help with what im missing to make this work.
Thanks,
See code bellow:
Dim sapFunc As New SAPFunctionsOCX.SAPFunctions
Dim objServer = sapFunc.Connection
objServer.Client = "101"
objServer.User = "MyUserName"
objServer.Ticket = "MyKey"
objServer.system = "PEC"
objServer.MessageServer = "MyMessagerServer"
objServer.GroupName = "PUBLIC"
If objServer.logon(0, True) <> True Then
MsgBox("Key Rejected")
Exit Sub
End If
Dim objRfcFunc As SAPFunctionsOCX.Function
objRfcFunc = sapFunc.Add("BAPI_FUNCLOC_GETLIST")
'System.Console.Write(objRfcFunc.Description)
If objRfcFunc.Call = False Then
MsgBox("Error occured - " & objRfcFunc.Exception)
Exit Sub
End If
Dim tab = objRfcFunc.Tables("FUNCLOC_LIST")
System.Console.WriteLine("Input start:")
For I = 1 To tab.RowCount
For j = 1 To tab.ColumnCount
System.Console.Write(tab.ColumnName(j) + ":")
System.Console.WriteLine(tab.Cell(I, j))
Next
Next
System.Console.WriteLine("Input end.")
I don't intend for this to be an answer, but if it helps then that's good. If it doesn't, I'll delete it.
With objRfcFunc.tables("funcloc_ra")
If .RowCount < 1 Then .Rows.Add
.cell(1, 1) = "I"
.cell(1, 2) = "EQ"
.cell(1, 3) = "Your Func Loc"
End With
Do this after setting objRfcFunc and before calling it. The call will use these parameters.
I means to Include, EQ means you want to find items equal to the value in low.

How to save the active "Word" document in VBScript?

Here I have a small VBS script that helps me append a new line to a table in MS "Word" 2003:
Set wd = CreateObject("Word.Application")
wd.Visible = True
Set doc = wd.Documents.Open ("c:\addtotable.doc")
Set r = doc.Tables(1).Rows.Add
aa = Split("turtle,dog,rooster,maple", ",")
For i = 0 To r.Cells.Count - 1
r.Cells(i + 1).Range.Text = aa(i)
Next
It works fine, but it doesn't save anything. I want it to save the performed changes.
By the method of macro-recording in the "Word" I got this macro command that saves active "Word" document:
ActiveDocument.Save
So, I decided to append this macro to the VBS script above:
Set wd = CreateObject("Word.Application")
wd.Visible = True
Set doc = wd.Documents.Open ("c:\addtotable.doc")
Set r = doc.Tables(1).Rows.Add
aa = Split("turtle,dog,rooster,maple", ",")
For i = 0 To r.Cells.Count - 1
r.Cells(i + 1).Range.Text = aa(i)
Next
ActiveDocument.Save
But it doesn't save anything. What am I doing wrong here?
Have you already tried calling doc.Save after making those changes? If that doesn't work:
The issue is that ActiveDocument doesn't automatically reference what you think it does in VBScript the way it does in Word's VBA.
Try setting a new variable to the active document, like so:
Dim activeDoc
Set activeDoc = wd.ActiveDocument
activeDoc.Save
I think you have to use ActiveDocument.SaveAs("C:\addtotable.doc"); because I can't find any documentation for .Save. SaveAs accepts a second parameter which specifies what format to save it in. Pastebin of the parameters here.

Resources