Warning: Ignoring Portion of Document... and AppendRTItem

Anyone have any advice / comments / words of wisdom on this?

I’m developing a DB which will have a form the user fills in and it send an e-mail with an attached button to add that information specified in the form. (Currently they manually edit the button and update the declaration section - I’m just trying to make it even easier). Anyway…

I’ve discovered, that if I append the current version of my button with subroutines - when the e-mail arrives we get the error message:

However, if I use the same button before I added the subroutines, it works fine. I can certainly live without the subroutines but I fail to understand why this makes a difference? Anyone have any advice?

I looked at this document and didn’t see anything that helped explain it: http://www-1.ibm.com/support/docview.wss?uid=swg21097112

My code to add the button:

Dim s As New NotesSession

Dim thisDB As NotesDatabase



Dim dc As NotesDocumentCollection



Dim thisDoc As NotesDocument

Dim EmailDoc As NotesDocument

Dim ButtonDoc As NotesDocument



Dim EmailBody As NotesRichTextItem

Dim TheButton As NotesRichTextItem



Dim searchstring As String



Set thisDB = s.CurrentDatabase

Set thisDoc = Source.Document

Set EmailDoc = thisDB.CreateDocument



If thisDoc.SentAlready(0) = "N" Then

	thisDoc.SentAlready="Y" ' Yes I need to add a save

	With EmailDoc

		.Form="Memo"

		.Subject = "Button Version 3.0 Alpha"

		.SendTo="Stephen M Christian/DIV/ORG"

	End With

	

	Set EmailBody = New NotesRichTextItem (EmailDoc, "Body")

	searchstring = |SELECT FORM="ButtonHolder"|

	

	Set dc = thisDB.search(searchstring, Nothing,0)

	If (dc.count = 1) Then

		Set ButtonDoc = dc.GetNthDocument(1)

		Set TheButton = ButtonDoc.GetFirstItem ( "TheButton" )

		

		Call EmailBody.AddNewLine(2) 

		Call EmailBody.AppendRTItem(TheButton)

		Call EmailBody.AddNewline(2)

		Call EmailBody.AppendText("This is a test.")

		Call EmailBody.AddNewline(2)

	End If

	

	Call EmailDoc.Send(False,EmailDoc.SendTo(0))

	Set EmailDoc = Nothing	

	

End If

Subject: Warning: Ignoring Portion of Document… and AppendRTItem

I would think that when you edit your RT to add subroutines Notes saves the result as 2 items. And IMO the method you use to merge will take just the first one. You can check in doc properties it you have 2 items “TheButton”.

The message about previous version is just something very approximate and misleading – usually telling you the RT is corrupt in some way.

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

So you were right there were actuall 5 Items in the worse case. I tried modiying my code as follows, it doesn’t loop. What am I missing? (Dots to just try and make it more readible)

. .Dim s As New NotesSession

. .Dim thisDB As NotesDatabase

. .

. .Dim dc As NotesDocumentCollection

. .

. .Dim thisDoc As NotesDocument

. .Dim EmailDoc As NotesDocument

. .Dim ButtonDoc As NotesDocument

. .

. .Dim EmailBody As NotesRichTextItem

. .Dim TheButton As NotesRichTextItem

. .Dim TheButtonI As NotesItem

. .

. .Dim searchstring As String

. .Dim c As Integer

. .

. .Dim t As Variant

. .

. .Set thisDB = s.CurrentDatabase

. .Set thisDoc = Source.Document

. .Set EmailDoc = thisDB.CreateDocument

. .

. .If thisDoc.SentAlready(0) = “N” Then

. . . .thisDoc.SentAlready=“Y”

. . . .Call thisDoc.Save(False,False)

. . . .With EmailDoc

. . . . . …Form=“Memo”

. . . . . …SendTo=“Stephen M Christian/BUS/ORG”

. . . .End With

. . . .

. . . .Set EmailBody = New NotesRichTextItem (EmailDoc, “Body”)

. . . .searchstring = |SELECT FORM=“ButtonHolder”|

. . . .

. . . .Set dc = thisDB.search(searchstring, Nothing,0)

. . . .If (dc.count = 1) Then

. . . . . .Set ButtonDoc = dc.GetNthDocument(1)

. . . . . .Call EmailBody.AddNewline(2)

. . . . . .c=0

. .’ Warning After this point do NOT resave TheButtonDoc

. . . . . .Set TheButtonI = ButtonDoc.GetFirstItem(“TheButton”)

. . . . . .Do Until TheButtonI Is Nothing

. . . . . . . .Call EmailBody.AppendRTItem(TheButtonI)

. . . . . . . .c=c+1

. . . . . . . .'Call ButtonDoc.RemoveItem(“TheButton”)

. . . . . . . .Call TheButtonI.Remove

. . . . . . . .Set TheButtonI = ButtonDoc.GetFirstItem(“TheButton”)

. . . . . .Loop

. . . . . .Call EmailBody.AddNewline(2)

. . . . . .Call EmailBody.AppendText(“This is a test.”)

. . . . . .Call EmailBody.AddNewline(2)

. . . .End If

. . . .

. . . .EmailDoc.Subject = “Button Version 3.0 Alpha loop=[” & Cstr(c) & “].”

. . . .Call EmailDoc.Send(False,EmailDoc.SendTo(0))

. . . .Set EmailDoc = Nothing

. .End If

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

what i meant by looping is something like this:

Forall i in buttonDoc.items

if i.name=“theButton” then

’ append or append and remove

’ it is possible that to do append & remove you might need to put first all these objects in a list or something. I think I’ve seen Notes is not too happy if you delete the current object within a loop. But you might try.

The way you are doing it – I think it is removing all items of the same name. Because Notes sometimes want us to think of all that as a single item. And again sometimes not.

There is one problem with all this. Not always you get really the next item; depending on what you do with it you may get the “first item” that we are trying to avoid in this way. That’s why I suggested removing those already processed.

End if

Next

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

Thanks for the help. I was NOT clear in my message the routines are actually a part of the button code. In one version of the button everything is in the “click” event and in the newer version I had the click event call a couple of subroutines I wrote to replace “common” process in the click event.

Older version which does NOT generate an error:

Newer version which gives the error message when appended:

Looking at the document properties I only see on Body field and no “TheButton” fields.

I can see the text in the body field, the button occurs after the 02-28 and before the “This is a test”

I’m going to try and add one routine at a time and see if that makes a difference.

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

Then I understood you correctly. I’m talking about the document where you define the buttons. In your code i see you use “TheButton” field. And that one I suspect gets split in two.

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

Well, a few more hours of testing various things and it looks like the problem has to do with the size of the item you’re attaching.

As I said I would, I started adding my subroutines back one by one. The error did not occur until I added back the last routine which was nothing more than a simple count:

Function NumberOfElements(s As String,delem As String) As Integer

Dim x As Integer



x=1

While Strtoken(s,delem,x)<>""

	x=x+1

Wend

NumberOfElements = x-1

End Function

So I removed an equal number of comment lines… Just to see, and ta da… The error message went away.

That’s crazy.

Just notice the GOOD e-mail is actually larger than the BAD e-mail. So the append must be failing to append everything and therefore causing the error.

The first line is of the e-mail I can open.

The second line is of the e-mail I cannot open.

The functional code in each is EXACTLY the same. Except in the 45.6 KB file I removed 10 lines of comments and (roughtly equal to the 10 lines of code above) and it works.

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

well, until you answer that you have check the document containing your button (place wher you add the subroutines, not the final doc) and can confirm that there is just one item TheButton, I would not say that it is crazy, but exactly that you should expect.

If it’s not so, then it’s definitely a magic.

If you confirm that you really got two or more items you could try to fix by looping through the items and attaching all items called theButton. This might not also work, but then you are able to try some related other approaches such as deleting the items you already appended (but not saving the doc of course).

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

I think I see what you mean. Yes, the original document does have two items “TheButton”… So you’re right I need to append them all. Let me try that next and see what happens.

Thanks for the suggestion.

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

Thanks!!!
Well, that had some interesting results, so I thought I would document them for anyone else who may have this problem.

I changed the code to see if we could just get “TheButton” to copy as per your suggestion.

. . . .Set dc = thisDB.search(searchstring, Nothing,0) . . . .

. . . .If (dc.count = 1) Then

. . . . . .Set ButtonDoc = dc.GetNthDocument(1) . . . . . .

. . . . . .c=0

. . . . . .Forall i In buttonDoc.items

. . . . . . . .If Ucase(i.name)=“THEBUTTON” Then

. . . . . . . . . .Set itm = buttonDoc.Items(c)

. . . . . . . . . .Call EmailDoc.CopyItem(itm,“TheButton”)

. . . . . . . .End If

. . . . . . . .c = c + 1

. . . . . .End Forall

. . . .End If

Results in all 5 of the “TheButton” moving over… HURRAY.

So I now had the TheButton in the code, but I didn’t see it in the RichText Body, so I changed the code as follows:

. . . .Set dc = thisDB.search(searchstring, Nothing,0)

. . . .If (dc.count = 1) Then

. . . . . .Set ButtonDoc = dc.GetNthDocument(1)

. . . . . .c=0

. . . . . .Forall i In buttonDoc.items

. . . . . . . .If Ucase(i.name)=“THEBUTTON” Then

. . . . . . . . . .Set itm = buttonDoc.Items(c)

. . . . . . . . . .Call EmailDoc.CopyItem(itm,“Body”)

. . . . . . . .End If

. . . . . . . .c = c + 1

. . . . . .End Forall

. . . .End If

Then the Warning Messge returned. Sob! Looking at document properties, I could see we had multiple “Body” fields which was a good sign, but they appeared to be out of order???

The Last Body field should be the “first” as this should appear before the button.

So I removed any AppendText before the above segment of code… And the warning message disappeared!! Woo Hoo!! I could have stopped here as I didn’t plan to add a lot of text anyway, but I thought I would try one more thing. I added a save after the appending of text and after I added the button. So my code now looks like this:

Call EmailBody.AppendText(“vvvv ---- Before ---- vvvv”)

Call EmailBody.AddNewline(2)

Call EmailDoc.Save(False,False)

Set dc = thisDB.search(searchstring, Nothing,0)

If (dc.count = 1) Then

. .Set ButtonDoc = dc.GetNthDocument(1)

. .c=0

. .Forall i In buttonDoc.items

. . . .If Ucase(i.name)=“THEBUTTON” Then

. . . . . .Set itm = buttonDoc.Items(c)

. . . . . .Call EmailDoc.CopyItem(itm,“Body”)

. . . .End If

. . . .c = c + 1

. .End Forall

End If

Call EmailDoc.Save(False,False)

Call EmailBody.AddNewline(2)

Call EmailBody.AppendText(“^^^^ ---- After ---- ^^^^”)

Call EmailDoc.Save(False,False)

EmailDoc.Subject = “Button Version 3.0 Alpha loop=[” & Cstr(c) & “].”

Call EmailDoc.Send(False,EmailDoc.SendTo(0))

Set EmailDoc = Nothing

I get an e-mail that opens (no warning) and the body field is multiple parts and it looks like everything is in in order:

A HUGE THANK YOU for the help!!!

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

great. I’m glad you managed to figure it out. This RT stuff sometimes gets quite tricky.

And it’s a good idea to leave the final solution/the code in this forum. You get something and you give something.

Good luck

Normunds

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

Yes, I’ve seen many a thread in the past where people have had a problem, and various responses on things to try. Then no follow up to ever indicate if they solved the problem or not and which answer worked best.

I hope this thread will be useful to someone else in the future.

Subject: RE: Warning: Ignoring Portion of Document… and AppendRTItem

Thanks!!!

Well, that had some interesting results, so I thought I would document them for anyone else who may have this problem.

I changed the code to see if we could just get “TheButton” to copy as per your suggestion.

. . . .Set dc = thisDB.search(searchstring, Nothing,0) . . . .

. . . .If (dc.count = 1) Then

. . . . . .Set ButtonDoc = dc.GetNthDocument(1) . . . . . .

. . . . . .c=0

. . . . . .Forall i In buttonDoc.items

. . . . . . . .If Ucase(i.name)=“THEBUTTON” Then

. . . . . . . . . .Set itm = buttonDoc.Items(c)

. . . . . . . . . .Call EmailDoc.CopyItem(itm,“TheButton”)

. . . . . . . .End If

. . . . . . . .c = c + 1

. . . . . .End Forall

. . . .End If

Results in all 5 of the “TheButton” moving over… HURRAY.

So I now had the TheButton in the code, but I didn’t see it in the RichText Body, so I changed the code as follows:

. . . .Set dc = thisDB.search(searchstring, Nothing,0)

. . . .If (dc.count = 1) Then

. . . . . .Set ButtonDoc = dc.GetNthDocument(1)

. . . . . .c=0

. . . . . .Forall i In buttonDoc.items

. . . . . . . .If Ucase(i.name)=“THEBUTTON” Then

. . . . . . . . . .Set itm = buttonDoc.Items(c)

. . . . . . . . . .Call EmailDoc.CopyItem(itm,“Body”)

. . . . . . . .End If

. . . . . . . .c = c + 1

. . . . . .End Forall

. . . .End If

Then the Warning Messge returned. Sob! Looking at document properties, I could see we had multiple “Body” fields which was a good sign, but they appeared to be out of order???

The Last Body field should be the “first” as this should appear before the button.

So I removed any AppendText before the above segment of code… And the warning message disappeared!! Woo Hoo!! I could have stopped here as I didn’t plan to add a lot of text anyway, but I thought I would try one more thing. I added a save after the appending of text and after I added the button. So my code now looks like this:

Call EmailBody.AppendText(“vvvv ---- Before ---- vvvv”)

Call EmailBody.AddNewline(2)

Call EmailDoc.Save(False,False)

Set dc = thisDB.search(searchstring, Nothing,0)

If (dc.count = 1) Then

. .Set ButtonDoc = dc.GetNthDocument(1)

. .c=0

. .Forall i In buttonDoc.items

. . . .If Ucase(i.name)=“THEBUTTON” Then

. . . . . .Set itm = buttonDoc.Items(c)

. . . . . .Call EmailDoc.CopyItem(itm,“Body”)

. . . .End If

. . . .c = c + 1

. .End Forall

End If

Call EmailDoc.Save(False,False)

Call EmailBody.AddNewline(2)

Call EmailBody.AppendText(“^^^^ ---- After ---- ^^^^”)

Call EmailDoc.Save(False,False)

EmailDoc.Subject = “Button Version 3.0 Alpha loop=[” & Cstr(c) & “].”

Call EmailDoc.Send(False,EmailDoc.SendTo(0))

Set EmailDoc = Nothing

I get an e-mail that opens (no warning) and the body field is multiple parts and it looks like everything is in in order:

A HUGE THANK YOU for the help!!!