Sorry I just can't figure it out (append numbers to a list)

Objective:End up with a list of the values for example in the StatusLog field, but with the newest value at the top.

Current problem:

Everything works OK, but the user has requested to have the field set so the latest value is at the top

Current idea(s) to resolve:

It’s a LotusScript Agent anyway, if we can do it in script :slight_smile:

Easiest would be to use some exisitng functionality like:

Forall m In CurrentStatusLog

		total = total + m

	End Forall

	doc.Total=Total

Except for somehow append a number to the start of each value in the total field, that represents it’s number in the list (Haven’t figured out how to do this yet!!)

If we could, then, I could use @Sort(NewFieldNameorValueorWhatever; [DESCENDING])

And I would think it would display the list in the preferred order, 10 (latest) at top, then 9 87654321 for example…then we’d have to clear the field, set it to that value, and remove all the numbering…

Anyone have a good way of doing this? Script or formula…

Here’s the whole of the current agent, that sets the ‘On Hold’ Status, for example:

Sub Initialize

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

'Call uidoc.Save

Dim Doc As NotesDocument

Set Doc = uidoc.Document

Dim tMainProjectPhase As Variant

tMainProjectPhase = doc.MainprojectPhase

Dim strMainProjectPhase As String

strMainProjectPhase = Cstr(tMainProjectPhase(0))

Dim user As String

user = session.CommonUserName

Dim NewStatus As String

NewStatus="On Hold"



Dim currentStatus As Variant

currentStatus = doc.ProjectStatus(0)



Dim OtherStatus As Variant

OtherStatus  = doc.Status(0)

doc.tmpOtherStatus = OtherStatus



Dim OldCmpStatus As Variant

OldCmpStatus = doc.CmpStatus(0)

doc.tmpOldCmpStatus = OldCmpStatus



'Messagebox =

' new code



If uidoc.Editmode Then

	Call uidoc.Reload

	Call uidoc.FieldAppendText _

	( "StatusLog", "," )

	Call uidoc.FieldAppendText _

	( "StatusLog", "The project status was changed from " +  Cstr(currentStatus)  + " to " + NewStatus + " by " + user  + " on " +Cstr(Date) + " at " + Cstr(Time) + ".") 

	Call uidoc.FieldAppendText _

	( "StatusLog", "," )

	

'Call uidoc.FieldSetText _

'( "LastChanged", "," )

	Call uidoc.FieldSetText _

	( "LastChanged", "The project status was last changed on " +Cstr(Date) + " at " + Cstr(Time) + ".") 

'Call uidoc.FieldSetText _

'( "LastChanged", "," )

	

	'uidoc.Refresh

	

	Call uidoc.Save

	doc.ProjectStatus=NewStatus

	doc.CmpStatus=NewStatus

	doc.SaveOptions=""

	Call Doc.Save(True,True)

	Call uidoc.Save

'Call uidoc.Close

	Call uidoc.Refresh

	Call Doc.Save(True,True)

	

Else

	Dim CurrentStatusLog As Variant

	CurrentStatusLog=doc.GetItemValue( "StatusLog" )

	Dim CurrentLastChanged As Variant

	CurrentLastChanged=doc.GetItemValue( "LastChanged" )

	

	

	Forall m In CurrentStatusLog

		total = total + m

	End Forall

	doc.Total=Total

	

	Eval2=Evaluate(|@ReplaceSubstring(total; "." ; "." + @NewLine)|,doc )

	

	Forall m In CurrentLastChanged

		total1 = total1 + m

	End Forall

	doc.Total1=Total1

	

	Eval3=Evaluate(|@ReplaceSubstring(total1; "." ; "." + @NewLine)|,doc )

	

	Eval=Evaluate(|@Char(13)|)

	'doc.StatusLog=Cstr(CurrentStatusLog(0)) +"," 

	' cold code=Cstr(CurrentStatusLog(0)) for line below

	doc.StatusLog=Cstr(Eval2(0)) + "The project status was changed from " +  Cstr(currentStatus)  + " to " + NewStatus + " by " + user  + " on " +Cstr(Date) + " at " + Cstr(Time) + "." 

	'doc.StatusLog=Cstr(CurrentStatusLog(0)) +","

'Call uidoc.FieldSetText _

'( "LastChanged", "," )

	doc.LastChanged= "The project status was last changed on " +Cstr(Date) + " at " + Cstr(Time) + "."

'Call uidoc.FieldSetText _

'( "LastChanged", "," )

	

	'uidoc.Refresh

	

	doc.ProjectStatus=NewStatus

	doc.CmpStatus=NewStatus

	doc.Status=NewStatus

	doc.SaveOptions=""

	Call Doc.Save(True,True)

	Call workspace.EditDocument(False, doc)

	'Call workspace.ViewRefresh

	'Call doc.Open

End If

End Sub

Subject: Sorry I just can’t figure it out (append numbers to a list)

Hi there,

Maybe I am missing something…

But why not make total = m + total as oppose to total = total + m

HTH,

Cheers… Mark

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

Maybe you are right…(and I misunderstood), but the current formula for total does not produce a list with e.g. numbers on it, just the values from the field (e.g. m is’nt actually appended to the list)…

Field Name: TOTAL

Data Type: Text List

Data Length: 1168 bytes

Seq Num: 70

Dup Item ID: 0

Field Flags: SUMMARY

“The project status was changed from Live to On Hold by Generic Notes Developer on 24/10/2006 at 15:47:53.The project status was changed from Live to On Hold by Generic Notes Developer on 24/10/2006 at 15:35:08.The project status was changed from On Hold to Live by Generic Notes Developer on 24/10/2006 at 15:35:31.The project status was changed from On Hold to Live by Generic Notes Developer on 24/10/2006 at 15:48:09.The project status was changed from Live to On Hold by Generic Notes Developer on 24/10/2006 at 15:52:58.The project status was changed from On Hold to Live by Generic Notes Developer on 24/10/2006 at 15:53:08.The project status was changed from Live to On Hold by Generic Notes Developer on 24/10/2006 at 15:58:51.The project status was changed from On Hold to Live by Generic Notes Developer on 24/10/2006 at 15:59:02.The project status was changed from Live to On Hold by Generic Notes Developer on 24/10/2006 at 15:59:35.The project status was changed from On Hold to Live by Generic Notes Developer on 24/10/2006 at 15:59:50.The project status was changed from Live to On Hold by Generic Notes Developer on 24/10/2006 at 15:59:57.The project status was changed from On Hold to Live by Generic Notes Developer on 24/10/2006 at 16:00:48.”

Subject: Sorry I just can’t figure it out (append numbers to a list)

Well, ignoring your current code, just concentrating on the objective:

Is your CurrentStatusLog field multi-value? Would be much easier if it was, then you can just set the field display settings to each value displaying on a new line.

To add a new line to the top of the field, if you use the uidoc methods is pretty easy, just get the current value of the field, then set the field to the newvalue + ", " + oldvalue. If you need back-end methods then you have to create a new array with one greater ubound than the field, assign the new value to 0, then loop through the field values adding to the array, finally assigning the new array to the field.

In order to sort the old values, it’s a matter of going through the current field, extracting the values one by one. Not sure whether it’s currently multivalue, so you may need to use a Left (or Right) statement to extract from each comma in the correct order, otherwise just loop through the field in reverse order. Create a new array and assign to the field.

hope that helps,

Dan

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

Hey again,

I guess I didn’t look that closely, Read Dan’s remarks…

Simply put though… instead of using uidoc.fieldappendtext set a temp var to the existing value and then add the existing log value to the new value then use a fieldsettext to set the field to its final value. I agree that this is easier to manipulate with a multi-value field but it is not necessary for your scenario.

Cheers,

Mark

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

Thanks Dan,

Now I get duplicate values, and they are still in the wrong order…unfortunately…

If uidoc.Editmode Then

	Call uidoc.Reload

	

	If uidoc.FieldGetText("StatusLog") ="" Then

		Call uidoc.FieldAppendText _

		( "StatusLog", "," )			

		Call uidoc.FieldAppendText _

		( "StatusLog", "The project status was changed from " +  Cstr(currentStatus)  + " to " + NewStatus + " by " + user  + " on " +Cstr(Date) + " at " + Cstr(Time) + ".") 

		Call uidoc.FieldAppendText _

		( "StatusLog", "," )

	Else

		StatusLogVal = uidoc.FieldGetText("StatusLog")		

		Call uidoc.FieldAppendText _

		( "StatusLog", "," )	

		Call uidoc.FieldAppendText _

		( "StatusLog", "The project status was changed from " +  Cstr(currentStatus)  + " to " + NewStatus + " by " + user  + " on " +Cstr(Date) + " at " + Cstr(Time) + ".") 

		Call uidoc.FieldAppendText _

		( "StatusLog", "," )

		Call uidoc.FieldAppendText _

		( "StatusLog",StatusLogVal)

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

So the code above is to add the new values at the top of the field? I would use:

dim StatusLogVal as string

StatusLogVal = uidoc.fieldgettext(“StatusLog”)

If StatusLogVal = “” Then

call uidoc.fieldsettext(“StatusLog”, "The project status was changed from " + Cstr(currentStatus) + " to " + NewStatus + " by " + user + " on " +Cstr(Date) + " at " + Cstr(Time) + “.”)

//–You have set currentstatus from a field, and date and time also I guess

Else

call uidoc.fieldsettext(“StatusLog”, "The project status was changed from " + Cstr(currentStatus) + " to " + NewStatus + " by " + user + " on " +Cstr(Date) + " at " + Cstr(Time) + “.,” + StatusLogVal)

End If

That should do it, although haven’t tested the syntax exactly.

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

Like my code, it gives subscript out of range.Additionally, it adds loads of duplicate values each time.

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

Thanks Dan,It is a multi-value field.

The existing values in existing documents don’t matter really, because it’s all still in development and they will be deleted.

I managed to convince the user that this is complicated and he can have it for the next release of the database.

I’ve added your code to that request so the developers can use it then. (including the caveat, I havent tested it either yet!!)

The field is MultiValue, and has Seperate Value when user enters Comma, Semi-Colon, and Newline and display sepeate values with newline.

Thanks Again

GND

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

Sorry, I don’t mean to be condescending, but the feature you are trying to implement is not difficult at all. If I understand you correctly, and if all you want to do is insert text so that the most recent entry is at the top, then the below code does just that. You might have to change some of the code based on how it is implemented (QuerySave, click of a button, etc.) Create a simple form with a field called ‘tmp’. The field is multi-value with display separate value in a new line selected. Put the code in an action button. Launch the Form in Notes client and click the button a few times and the new entries will be inserted at the top.

--------Dim wSpace As New NotesUIWorkspace

--------Dim uiDoc As NotesUIDocument

--------Dim doc As NotesDocument

--------Dim item As NotesItem

--------Dim varValues As Variant

--------Set uiDoc = wSpace.CurrentDocument

--------Set doc = uiDoc.Document

--------Set item = doc.GetFirstItem( “tmp” )

--------If item.Values(0) = “” Then

----------------item.Values = "Text inserted at " & Now

--------Else

----------------varValues = item.Values

----------------item.Values = “”

----------------item.Values = "Text inserted at " & Now

----------------Call item.AppendToTextList( varValues )

--------End If

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

Yes, as a standalone function, it is easy.

Just cause I convinced the user is complicated doesn’t mean I think it is!

The complexity comes with combining it with the current code, and preventing duplicate values being inserted.

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

I, respectfully, disagree with your statements. We have done it at our end, and that was the only reason I responded with an example. However, I do realize that my example was very simplistic in nature, but I was only trying to demonstrate one of the ways by which you can achieve what you are planning to implement. The example can be easily expanded to remove duplicates, number the log entries and, finally, integrate with any existing code.

By the by, why would you convince a user that something is complicated when you don’t think it is? Isn’t the argument that you are providing contradictory?

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

I could do it myself with an LS equivalent of @Sort.This was working, but no longer for some reason…and can’t be triggered by my LS agent, and doesn’t work without the prompt bit…but it was sorting them!

(Course still have to get rid of the number it adds)

@If(@Elements(StatusLog) = 0; @Return(0); “”);

n := 1;

@DoWhile(

	@Prompt([Ok]; "StatusLog" + @Text(n); StatusLog[n]);

	@SetField("DeleteThisField"; DeleteThisField + @NewLine + @Text(n) + StatusLog[n]);

	n := n + 1;

n <= @Elements(StatusLog)

);

@SetField(“StatusLog”;“”);

@SetField(“StatusLog”;DeleteThisField);

@All

Subject: RE: Sorry I just can’t figure it out (append numbers to a list)

And this is to sort out all the older documents? I need to know whether the field is multivalue or not. By the looks of things on one of your previous posts it’s not which complicates things slightly (I’d still convert it to multi-value if it isn’t yet).

To convert a multi-value field the way you want this should work:

dim item as notesitem

set item = doc.getfirstitem(“StatusLog”)

dim newfieldarray() as string

dim index as integer

index = ubound(item.values)

for i = 0 to ubound(item.values)

redim preserve newfieldarray(i)

newfieldarray(i) = item.values(index)

index = index - 1

Next

doc.statuslog = newfieldarray