Reputation: 17
Can anyone help me understand what this piece of VBScript is doing. I get lost on the WhereClause bit
If CVs = "," or CVs = ",," Then
ExistingSupplierCVs = 0
Else
Set CVRecords = Ext.CreateAppRecordList( ActivityTableId )
WhereClause = Left(CVs, Len(CVs)-1)
WhereClause = Right(WhereClause, Len(WhereClause)-1)
WhereClause = "TS_ID in (" & WhereClause & ") and TS_SUPPLIER = " & Supplier
If Not CVRecords.ReadWithWhere( WhereClause ) then
Call Ext.LogErrorMsg( "TeamScript Error : Cannot find " & QUOTE & WhereClause & QUOTE & " in table " & QUOTE & "USR_ACTIVITY" & QUOTE )
Exit Sub
End If
ExistingSupplierCVs = CVRecords.Length()
End If
Upvotes: 0
Views: 167
Reputation: 1026
Because this is AppScript (the VBScript variant for SBM) you'll get better answers posting this to the Serena (now part of MicroFocus) Community site.
Upvotes: 0
Reputation: 1
This is very typical to the Serena Business Manager Composer language - AppScript.
The code which you have shared would be to count the number of records in a Multi Relation field and then enter the value in a field. A typical empty Multi Relational fields looks like this ",," and will values it will look something like this ",1,34," with the numbers showing the Ids of the field which this MR field is pointing to.
The where clause which is being built is nothing but simply removing the first and the last comma from the MR field and then query for the Ids.
let me know if you still have any doubts here.
Upvotes: 0
Reputation:
Like @Dave stated: They are removing the first and last characters from the CVs
string.
A simpler approach would be to use Mid
WhereClause = Mid(CVs, 2, Len(CVs) - 2)
You could combine all three lines like this:
WhereClause = "TS_ID in (" & Mid(CVs, 2, Len(CVs) - 2) & ") and TS_SUPPLIER = " & Supplier
Upvotes: 1
Reputation: 4356
Best guess is as below...
If CVs = "," or CVs = ",," Then
ExistingSupplierCVs = 0 ' if the string is empty advise that the number of CVs is zero
Else
Set CVRecords = Ext.CreateAppRecordList( ActivityTableId ) ' extract a list of CVRecords
WhereClause = Left(CVs, Len(CVs)-1) ' strip the last char from this string
WhereClause = Right(WhereClause, Len(WhereClause)-1) ' strip the first char from this string
WhereClause = "TS_ID in (" & WhereClause & ") and TS_SUPPLIER = " & Supplier ' insert the values into (presumably) a SQL query
If Not CVRecords.ReadWithWhere( WhereClause ) then ' if executing the query returns false
Call Ext.LogErrorMsg( "TeamScript Error : Cannot find " & QUOTE & WhereClause & QUOTE & " in table " & QUOTE & "USR_ACTIVITY" & QUOTE ) 'report an error and exit the subroutine.
Exit Sub
End If
ExistingSupplierCVs = CVRecords.Length() ' return the number of records from the query
End If
Upvotes: 0