Get more strings values in one dialog? - dialog

how to get more (at least>5) strings values in one dialog?
like below, I can get the string value of str1
string str1
GetString("studentID", " ", str1)
If there are 6 strings, is there a way I can get the values of all 6 strings in one dialog?

The basic script commands for premade dialogs only support the simplest use-cases. For any type of dialog which does more, you have to create your own dialog class and object.
This isn't so hard, though. Please refer to the F1 help section on dialogs here:
In fact, your exact question is covered in the example section of the F1 help here:
Based on this example, a method that gives a 6-string dialog would look f.e. like:
number GetSixStringsDialog( string &str1, string &str2, string &str3, string &str4, string &str5, string &str6 )
{
TagGroup DLG, DLGItems
DLG = DLGCreateDialog( "Please enter strings", DLGItems )
TagGroup val1tg, val2tg, val3tg, val4tg, val5tg, val6tg
DLGitems.DLGAddElement( DLGCreateStringField( "1st: ", val1tg, str1, 30 ) )
DLGitems.DLGAddElement( DLGCreateStringField( "2nd: ", val2tg, str2, 30 ) )
DLGitems.DLGAddElement( DLGCreateStringField( "3rd: ", val3tg, str3, 30 ) )
DLGitems.DLGAddElement( DLGCreateStringField( "4th: ", val4tg, str4, 30 ) )
DLGitems.DLGAddElement( DLGCreateStringField( "5th: ", val5tg, str5, 30 ) )
DLGitems.DLGAddElement( DLGCreateStringField( "6th: ", val6tg, str6, 30 ) )
number result = Alloc( UIframe ).Init( DLG ).Pose()
str1 = val1tg.DLGGetStringValue()
str2 = val2tg.DLGGetStringValue()
str3 = val3tg.DLGGetStringValue()
str4 = val4tg.DLGGetStringValue()
str5 = val5tg.DLGGetStringValue()
str6 = val6tg.DLGGetStringValue()
return result
}
string s1,s2,s3,s4,s5,s6
s1 = "PreText 1"
s4 = "PreText 4"
if ( !GetSixStringsDialog( s1, s2, s3, s4 ,s5, s6 ) )
Throw( "User cancel" )
Result( "\n Entered strings are:" )
Result( "\n1:" + s1 )
Result( "\n2:" + s2 )
Result( "\n3:" + s3 )
Result( "\n4:" + s4 )
Result( "\n5:" + s5 )
Result( "\n6:" + s6 )

Related

Replace multiple spaces with semi-colon in a string in powerscript

Given a string like (2 5). I want to replace multiple spaces with a semi-colon in a string (2 5) in PowerBuilder
Thanks in Advance
This can be done with a regular expression. But the support for regular expression in Powerscript is minimal, you need to use an external COM object like VBScript.RegExp to do something useful.
OLEObject re
int li_retcode
string s
string value
re = Create OLEObject
li_retcode = re.ConnectToNewObject("VBScript.RegExp")
re.Pattern = "\s\s+"
re.Global = True
s = "4 2"
value = re.Replace("4 2" , ";")
MessageBox("", value) // 4;2
re.DisconnectObject()
simply cut out each word, trim and join into a string.
string ls_key = '2 5 8 9'
string ls_new = ''
long ll_pos
do
ll_pos = Pos( ls_key, ' ')
if ll_pos > 0 then
ls_new += trim( left( ls_key, ll_pos - 1) ) + ':'
ls_key = trim( mid( ls_key, ll_pos + 1 ) )
else
ls_new += trim( ls_key )
ls_key = ''
end if
loop while ll_pos > 0
return ls_new

Single Speechmarks not added to numbers

I have the below Code which works, except for if there is a number in the text field so a single speech mark does not get added around say 1 but would be around one.
As an aside I don't want speechmarks on the first column (the ID value)
SEP = ", "
QUOTE = "\'"
NEWLINE = System.getProperty("line.separator")
KEYWORDS_LOWERCASE = com.intellij.database.util.DbSqlUtil.areKeywordsLowerCase(PROJECT)
KW_INSERT_INTO = KEYWORDS_LOWERCASE ? "insert into " : "INSERT INTO "
KW_VALUES = KEYWORDS_LOWERCASE ? ") values (" : ") VALUES ("
KW_NULL = KEYWORDS_LOWERCASE ? "null" : "NULL"
def record(columns, dataRow) {
OUT.append(KW_INSERT_INTO)
if (TABLE == null) OUT.append("MY_TABLE")
else OUT.append(TABLE.getParent().getName()).append(".").append(TABLE.getName())
OUT.append(" (")
columns.eachWithIndex { column, idx ->
OUT.append(column.name()).append(idx != columns.size() - 1 ? SEP : "")
}
OUT.append(KW_VALUES)
columns.eachWithIndex { column, idx ->
def value = dataRow.value(column)
def stringValue = value != null ? FORMATTER.format(dataRow, column) : KW_NULL
if (DIALECT.getDbms().isMysql())
stringValue = stringValue.replace("\\", "\\\\")
OUT.append(skipQuote ? "": QUOTE).append(stringValue.replace(QUOTE, QUOTE + QUOTE))
.append(skipQuote ? "": QUOTE).append(idx != columns.size() - 1 ? SEP : "")
}
OUT.append(");").append(NEWLINE)
}
ROWS.each { row -> record(COLUMNS, row) }
Not 100% sure what and why you are trying to achieve, but I would write down something like that in idiomatic groovy:
LinkedHashMap.metaClass.value = { delegate.get it } // mock value()
TABLE = [ parent:[ name:'OTHER_TABLE' ] ] // fake TABLE
KEYWORDS_LOWERCASE = true // false
KW_INSERT_INTO = 'INSERT INTO'
KW_VALUES = 'VALUES'
if( KEYWORDS_LOWERCASE ){
KW_INSERT_INTO = KW_INSERT_INTO.toLowerCase()
KW_VALUES = KW_VALUES.toLowerCase()
}
COLUMNS = [ 'a', 'nullllll', 'c', 'numberString' ]
String record(columns, dataRow) {
List values = columns.collect{
def v = dataRow.value it
switch( v ){
case Number:
case ~/\d+/: return v
case String: return "'$v'"
default: return 'null'
}
}
"$KW_INSERT_INTO ${TABLE?.parent?.name ?: 'MY_TABLE'} (${columns.join( ', ' )}) $KW_VALUES (${values.join( ', ' )});\n"
}
String res = record( COLUMNS, [ a:'aa', c:42, numberString:'84' ] )
assert res == "insert into OTHER_TABLE (a, nullllll, c, numberString) values ('aa', null, 42, 84);\n"
In switch statement the values are getting formatted.
You can try out yourself at https://groovyconsole.appspot.com/script/5151418931478528

Groovy script stripping single quotes out of input

I have a need to convert log messages into JSON, so I decided to write a groovy script to try and accomplish the task. The log messages look like:
InvoiceAdjustment{invoiceAdjustmentId=null, invoiceAdjustmentType='REFUND', invoiceId=20231189, currencyCode='USD', shippingRefundAmount=0.00, shippingRefundAmountUsd=0.00, taxTariffRefundAmount=0.00, taxTariffRefundAmountUsd=0.00, salesTaxTotalRefundAmount=0.00, salesTaxTotalRefundAmountUsd=0.00, vatRefundAmount=0.00, vatRefundAmountUsd=0.00, invoiceAdjustmentItems=[InvoiceAdjustmentItem{invoiceAdjustmentItemId=null, invoiceLineItemId=411729, refundAmount=3.82, refundAmountUsd=3.82, salesTaxRefundAmount=0.00, salesTaxRefundAmountUsd=0.00, returnQuantityExpected=0, returnQuantityActual=0, keptEnrolled=false, cancelShip=true, cancellationSuccessful=true, reshipQuantity=0, relativeLineNumber=4, sku='NTN-CHCK-339CV-NS163880', created=null, createdBy=null}], billingType='BRAINTREE', externalTransactionId='c3rvz7bv', refundTransactionId='null', reason='WAREHOUSE_CANCELLED', reshipmentInvoiceId=null, created=null, createdBy=null, refundedOn=null, notes='Cancelled by warehouse', createdByName='null', createdByEmail='null'}
When iterating through these (using String... args) it appears all single quotes (which I want to key off to know if a field is a string) are gone! For example, the SKU field which is surrounded with single quotes in the input, prints as "sku=NTN-CHCK-339CV-NS163880," -- no quotes!
Is there a way to keep the single quotes from the input so I can replace them in my script?
Here is the script in its entirety:
class LogToJson
{
static void main( String... args )
{
if ( args.length == 0 )
{
println( "Error, you must provide a string." )
}
StringBuilder jsonBuilder = new StringBuilder()
for ( String token : args )
{
if ( token.contains( "{" ) )
{
token = token.contains( "[" ) ? "\"" + token.substring( 0, token.indexOf( '[' ) - 1 ) + "\"=[{"
: "" +
"{\"" + token.substring( token.indexOf( "{" ) + 1, token.indexOf( "=" ) ) + "\"" + token.substring( token.indexOf( "=" ) )
}
else if ( token.contains( '=' ) )
{
token = "\"" + token.substring( 0, token.indexOf( '=' ) ) + "\"" + token.substring( token.indexOf( '=' ) )
}
token = token.replaceAll( '=', ':' ).replaceAll( "\'", "\"" )
jsonBuilder.append( token + ' ' )
}
println( jsonBuilder.toString() )
}
}
Edited to add: It appears if I escape all the single quotes in the input (i.e. replace ' with \' before using it as input) the script works as expected. Ideally, I'd rather not have to do this.

Notepad can not find symbol for Average, max, min, etc

First, this is a homework assignment. I am supposed to create a program using a switch command. It asks the user to input 3 integers, then input an integer of 1-5 for the five cases average, max, min, total, and exit. I have pretty much completed this program, first having a user input 3 integers, then creating the switch "menu" structure, and inside each case, I attempted to create the mathematics for each of the arithmetic functions.
My error message is "cannot find symbol", which is a broad and vague error message to post about. Everything I have Googled, or found on this site seems to be unrelated to the specific symbols that my program is missing, and/or can be typographical in nature. So, unfortunately, I've had to create another thread about this.
My program can not find the symbols average, max, min, and et cetera. I believe that I may have done my arithmetic algorithms wrong, and they are either not initialized properly or at all, or I need to set them to zero before the switch command is ever used.
I'll need to post the code so you can see what I have done:
>public static void main( String args[] )
{
// Attempting to initialize the 3 integers AND the user-input early on
int n1, n2, n3, n4;
Scanner sc = new Scanner( System.in);
while ( true )
{
System.out.println ( "Please give three integers separated by spaces: " );
n1 = sc.nextInt();
n2 = sc.nextInt();
n3 = sc.nextInt();
// building a menu - hoping integers aboive will work in Switch command
System.out.println( "\n****** Analysis Menu ******" );
System.out.println( "1: Average" );
System.out.println( "2: Maximum" );
System.out.println( "3: Minimum" );
System.out.println( "4: Total" );
System.out.println( "5: Exit" );
System.out.println( "*******************\n" );
n4 = sc.nextInt(); // get the user selection
if ( n4 == 1 )
{
Average = n1 + n2 + n3 / 3;
System.out.print( "Average = " + Average );
}
else if ( n4 == 2 )
{
max = n1;
if ( max < n2 ) max = n2;
if ( max < n3 ) max = n3;
System.out.println( "Maximum = " + max );
}
else if ( n4 == 3 )
{
min = n1;
if ( min > n2) min = n3;
if ( min > n3) min = n2;
System.out.print( "Minimum = " + min );
}
else if ( n4 == 4 )
{
total = sum;
System.out.print( "total = " + total );
}
else if ( n4 == 5 )
{
System.out.println( "You have selected Exit." );
break;
}
else
{
System.out.println( "No such selection exists." );
The error messages say they cannot find every total, min, max, average, and sum in this. So I am not sure if I need to initialize them somehow, set them to 0, or even how to do that in this context.
There are multiple issues in above code:
1. Average, min, max variable not defined.
2. You average logic is not right.
3. You are missing end brace.
I tried to modify these and this is what i came up with.
public static void main( String args[] )
{
// Attempting to initialize the 3 integers AND the user-input early on
int n1, n2, n3, n4;
int Average, max, min, total;
Scanner sc = new Scanner( System.in);
while ( true )
{
System.out.println ( "Please give three integers separated by spaces: " );
n1 = sc.nextInt();
n2 = sc.nextInt();
n3 = sc.nextInt();
// building a menu - hoping integers aboive will work in Switch command
System.out.println( "\n****** Analysis Menu ******" );
System.out.println( "1: Average" );
System.out.println( "2: Maximum" );
System.out.println( "3: Minimum" );
System.out.println( "4: Total" );
System.out.println( "5: Exit" );
System.out.println( "*******************\n" );
n4 = sc.nextInt(); // get the user selection
if ( n4 == 1 )
{
Average = (n1 + n2 + n3) / 3;
System.out.print( "Average = " + Average );
}
else if ( n4 == 2 )
{
max = n1;
if ( max < n2 ) max = n2;
if ( max < n3 ) max = n3;
System.out.println( "Maximum = " + max );
}
else if ( n4 == 3 )
{
min = n1;
if ( min > n2) min = n3;
if ( min > n3) min = n2;
System.out.print( "Minimum = " + min );
}
else if ( n4 == 4 )
{
total = n1 + n2 + n3;
System.out.print( "total = " + total );
}
else if ( n4 == 5 )
{
System.out.println( "You have selected Exit." );
break;
}
else
{
System.out.println( "No such selection exists." );
}
}
}
You need to define Average,min,max,total as a variable just like n1,..,n4. I mean
decimal Average;
BTW it's better to avoid naming variable like this for example minValue or maxValue are better in naming.

Javascript vs. Lotusscript

I am hoping someone can put me out of my misery here. I rewrote a LotusScript function in JavaScript and it is not working as it should be. I can't look at this thing anymore. I"m hoping someone can help me figure this out.
The function takes a name of a group and an address book db object. It fetches and returns all the members of that group including nested groups. It works great in the Lotusscript version but not in the Javascript version. It's something to do with the recursive function and the index into the array's.
If you create two groups. Put 10 names in the first group and 5 names in the second group. Note, Name the second group with a leading # to make it sort to the top of the first group
group-A
1group-A
bla
bla2
bla3
bla4
bla5
bla6
bla7
bla8
bla9
bla10
1group-A
other1
other2
other3
other4
other5
In the Javascript version when you pass the function group-A it returns 10 names. Five from the second group and the second five from the first group.
Here is the code for the lotusscript version
Function LibGetGroupMembers( groupName As String, addressBook As NotesDatabase ) As Variant
' This Function takes a passed in group name and gets all the members of that group.
' Not a big whoop until you consider nested group names. This is a recursive routine.
'
' Inputs : Name of the group to fetch the members of.
'
' Uses : Global objects
'
' Outputs : Returns an array of members
'
' History:
' 02.19.2001 - Steven Rieger : Created Function.
Dim groupView As NotesView
Dim groupMainDoc As NotesDocument
Dim groupMembers As Variant
Dim nestedGroupMembers As Variant
Dim arrayOfMembers() As String
Dim mainIndex As Integer
Dim nestedIndex As Integer
Dim resultIndex As Integer
On Error Goto ErrorHandling
gLibObjectName = CStr( GetThreadInfo(1) ) & " - " & gLibDatabaseNamePath
gLibErrorMessage = "Begin " & gLibObjectName
Call LibLogErrorPushCallingPgm ( gLibErrorMessage )
Print( gLibErrorMessage )
gLibAdditionalErrorMessage = "Fetching Group View From NAB"
Set groupView = addressBook.GetView( "($VIMGroups)" )
If( groupView Is Nothing ) Then
Call LibLogError( "Error: Un-able to get view from address book", gLibErrorMessage )
Exit Function
End If
gLibAdditionalErrorMessage = "Fetching Group Main Document " & groupName
Set groupMainDoc = groupView.GetDocumentByKey( groupName, True )
resultIndex = 0
Redim arrayOfMembers( 0 )
' Did we find a matching group document?
If Not( groupMainDoc Is Nothing ) Then
If Not( Iselement ( gListOfGroupNames( Lcase( groupName ) ) ) ) Then
' Print( "Processing Group: " & groupName )
gListOfGroupNames( Lcase( groupName ) ) = " "
groupMembers=groupMainDoc.GetItemValue( "Members" )
For mainIndex = Lbound( groupMembers ) To Ubound( groupMembers)
nestedGroupMembers= LibGetGroupMembers( groupMembers( mainIndex ), addressBook )
If( nestedGroupMembers(0) = "" ) Then
If( groupMembers( mainIndex ) <> "" ) Then
Redim Preserve arrayOfMembers( Ubound( arrayOfMembers ) + 1)
arrayOfMembers( resultIndex ) = groupMembers( mainIndex )
resultIndex = resultIndex + 1
End If
Else
Redim Preserve arrayOfMembers( Ubound( nestedGroupMembers ) + resultIndex )
For nestedIndex = Lbound( nestedGroupMembers ) To Ubound( nestedGroupMembers )
arrayOfMembers( resultIndex ) = nestedGroupMembers( nestedIndex )
resultIndex = resultIndex + 1
Next
End If
Next
If( arrayOfMembers( Ubound( arrayOfMembers ) ) = "" And Ubound( arrayOfMembers ) > 0 ) Then
Redim Preserve arrayOfMembers( Ubound( arrayOfMembers ) - 1 )
End If
Else
groupName = "*** Circular Group: " & groupName & " ***"
End If
End If
LibGetGroupMembers = arrayOfMembers
Goto Bye
ErrorHandling :
Call LibLogError( "Error: " & Err( ) & ": " & Error( ) & Chr( 13 ) & Chr( 13 ) & "Occured in Module " & CStr( GetThreadInfo(1) ) & " at Line Number: " & Erl(), CStr( GetThreadInfo(1) & " - " & gLibDatabaseNamePath ) )
Resume Bye
Bye:
gLibAdditionalErrorMessage = "End " & CStr( GetThreadInfo(1) & " - " & gLibDatabaseNamePath )
' This will pop the last entry of the stack!
Call libLogErrorPopCallingPgm()
Print( gLibAdditionalErrorMessage )
End Function
HERE IS THE CODE FOR THE JAVASCRIPT FUNCTION
function jsLibGetGroupMembers( groupName:string, addressBook:NotesDatabase )
{
// This Function takes a passed in group name and gets all the members of that group.
// Not a big whoop until you consider nested group names. This is a recursive routine.
//
// Inputs : Name of the group to fetch the members of.
//
// Uses : Global objects
//
// Outputs : Returns an array of members
//
// History:
// 02.19.2001 - Steven Rieger : Created Function.
var groupView:NotesView;
var groupMainDoc:NotesDocument;
var groupMembers:java.util.Vector;
var nestedGroupMembers = new Array();
var arrayOfMembers = new Array();
var mainIndex:Integer;
var nestedIndex:Integer;
var resultIndex:Integer;
print( "Begin jsLibGetGroupMembers - Passed in Name: " + groupName );
groupView = addressBook.getView( "($VIMGroups)" )
if( groupView == null )
{
print( "group document not found!" );
return nestedGroupMembers;
}
// gLibAdditionalErrorMessage = "Fetching Group Main Document " & groupName
groupMainDoc = groupView.getDocumentByKey( groupName, true )
resultIndex = 0
// Did we find a matching group document?
if( groupMainDoc != null )
{ // is the group name already in the global list of groups?
if( !(groupName.toLowerCase() in gListOfGroupNames ) )
{
// Add the group name to the globla list of groups to prevent processing duplicate groups
gListOfGroupNames[ groupName.toLowerCase() ] = " "
groupMembers = groupMainDoc.getItemValue( "Members" );
for( groupMemberIndex = 0; groupMemberIndex < groupMembers.length; groupMemberIndex++ )
{
// Fetch any nested group members if the current member is a group name
nestedGroupMembers = jsLibGetGroupMembers( groupMembers[groupMemberIndex], addressBook );
if ( typeof nestedGroupMembers[0] === 'undefined' || nestedGroupMembers[0] === null )
{
// If no group was found and we have an actual member name add it to the list.
if( groupMembers[groupMemberIndex].length > 0 )
{
print( "adding user to array: " + groupMembers[groupMemberIndex] + " resultIndex = " + resultIndex );
arrayOfMembers[resultIndex] = groupMembers[groupMemberIndex];
resultIndex += 1;
}
else
{
print( "No User to Add!");
}
}
else
{
// If this was a nested group we found add the members of that group to the list
for( nestedGroupMemberIndex = 0; nestedGroupMemberIndex < nestedGroupMembers.length; nestedGroupMemberIndex++ )
{
print( "adding nested user to array: " + nestedGroupMembers[nestedGroupMemberIndex] + " resultIndex = " + resultIndex );
arrayOfMembers[ resultIndex ] = nestedGroupMembers[nestedGroupMemberIndex];
resultIndex += 1;
}
}
}
}
else
print( "Duplicate Group!");
}
else
{
print( "no group doc found!" );
}
print( "exiting jsLibGetGroupMembers: " + "\n" + arrayOfMembers );
return arrayOfMembers;
}
This answer will no doubt seem ironic given my recent blog post, but here's an SSJS implementation that will return a sorted list of all members of a group hierarchy:
var AtFunctions = (function() {
function getGroupNames (groupRecord, serverName) {
var result = new java.util.TreeSet();
if (groupRecord) {
for (var eachMember in groupRecord.getItemValue("Members")) {
var nestedGroupRecord = getGroupRecord(eachMember, serverName);
if (nestedGroupRecord) {
result.addAll(getGroupNames(nestedGroupRecord, serverName));
nestedGroupRecord.recycle();
} else {
result.add(eachMember);
}
}
}
return result;
}
function getGroupRecord (groupName, serverName) {
var result = null;
try {
serverName = (serverName || session.getServerName());
var NAB = session.getDatabase(serverName, "names.nsf");
var groupView = NAB.getView("($VIMGroups)");
result = groupView.getDocumentByKey(groupName, true);
} catch (e) {
print("Error getting group record: " + e.toString());
}
return result;
}
var API = {
expandNameList: function(groupName, serverName) {
var result = new java.util.TreeSet();
if (groupName) {
var groupRecord = getGroupRecord(groupName, serverName);
if (groupRecord) {
result.addAll(getGroupNames(groupRecord, serverName));
groupRecord.recycle();
}
}
return result;
}
};
return API;
})();
var #ExpandNameList = AtFunctions.expandNameList;
The variable alias at the end will allow you to treat this as a custom #Function, if desired, so you can call this one of two ways:
var groupMembers = #ExpandNameList("All Employees");
var groupMembers = AtFunctions.expandNameList("All Employees");
// in either syntax, you can optionally pass a server name as a second argument
NOTE: it's using the Java TreeSet class instead of JavaScript arrays, which has the following benefits:
It's automatically sorted. You might not want this, but for this
type of operation, it's often useful.
It automatically ignores duplicates, so you should only get one instance of each name even if the same member exists in multiple subgroups.
Syntactically, it's just so much easier to manipulate than an array.
Enjoy. :)

Resources