Link to home
Start Free TrialLog in
Avatar of madheeswar
madheeswarFlag for Singapore

asked on

Table and appending rows with data

Dear Experts,
I know this problem may be difficult but I expect some solutions.

NOTE: This is for Notes and WEB.

here is the problem,

I have 2 fields which are called Next Actoin and Last Action (For the time being)

Whenever there is a change in LastAction field, I want to append the old value to a field (like History for reviews) and at the same time append the value of NextAction.

the above requirement is easy and I achieved in both(Web & Client)

Now the tricky part is:

I want both the results display in a table. Whenever there is appending, need to display in a new row.(Don't suggest me to use multi value separator and newline. I used it). i.e., I want to display as a table with rows whenever there is a change and appending. Means new change , new row should be added to the table with this value.


And another one is, if the nextaction value is not changed for past 3 times, a mail should be sent.

And my understanding is it cannot be done.I want you guys to prove me WRONG.

I saw lot of suggestions to use RTF fields. Still I bet it may not be achieved.


This question analyzes my knowledge on Notes. Lets see at what point i have reached(beginner/Junior/Developer/Medium/Average/Good/VeryGood/Senior).

So, EXPERTS, please help in this.

~Thanks
madheeswar
Avatar of madheeswar
madheeswar
Flag of Singapore image

ASKER

Guys,
Please don't suggest to use any 3rd party softwares.


Thanks.
R6 ?
R5->NOTES & WEB
This can be done, but it will still be an akward solution in RTfield;  I can suggest an alternative, however.

1. RTF : use the RTF Lotusscript library you can find on Martin Scott :
http://www.martinscott.com/DesignLibrary.nsf/scategory/D0211DEA704D91CA85256C08001DF283?opendocument
I've used this in the past, works great.  To do what you want, you'll need to clean out the RTF field, and regenerate the RTF table for every change.  You'll have to save the document, and reopen it to display the changes to the user (in the client)

2. Embedded view: store the Actions, not in fields on the document, but in separate documents.  Now use an embedded view to show these documents.  Works both in the Client and on the web, and is a nice clean solution.

cheers,

Tom
In R6, you could code this using Native Notes lotusscript, and you wouldn't have to close the document first.  Still, the embedded view solution works nicer in R6 too.  BTW, make the documents response documents, and create the view sorted on Parent ID (@text($Ref)).  Now use a 'Show Single Category' to select only the relevant documents.


cheers,

Tom
Avatar of HappyFunBall
HappyFunBall

If it needs to be a RTF, there's another way to make this work.  Create a form with one row of a table in it and fields for all the cells you'd like to fill in that table.  You can format it anyway you'd like.  You'll then need to write some lotusscript to create a new document based on that form, populate the fields on it with the Last Action data, and then use the doc.RenderToRTItem method to append a copy of that one-row document into your RTF.  As Bozzie4 mentioned, you'll need to save and reopen the document to show the change to the user.

Downside is that it will not be a true table, rather a bunch of one row tables stacked above each other.  

Upside is you'll have good control on the formatting and you get to keep all the data in one document.
Mady,
In web it can be easily achieved using DOM.
Assuming your multivalue field to be nextaction


Put this in ur HTMLHEad

tab := @Char(32) + @Char(32);

jsr := @If( nextaction != ""; @Implode( "array_responses[array_responses.length] = \"" + nextaction + "\";" + @NewLine ); "" );

"" + @NewLine + @NewLine



Now in jsr u have all the values as a array


in the onload u can use createelement and create a table and tr tag.. let me know if u need code or just see this link to create


http://www.mozilla.org/docs/dom/technote/tn-dom-table/#creating


For Notes client : You can use front end classes and manipulate

Partha
There are no suitable frontend classes you can use in the client.

Why would you btw bother with DOM ?  Creating a simple textfield or even computed text will do :

Nextlines := "<tr><td>"+NextAction+"</td>";
LastLines := "<td>"+ LastAction+"</td></tr>";
"<table>"+
@implode(LastLines;"")+
@implode(NextLines;"")+
"</table>"

Still, this will only work on the web (is a good solution for R6 though)

cheers,

Tom
The embedded view (Bozzie's second suggest) is definitely easiest.

Or, you could use the API directly.. you don't need third-party products to do this, but it certainly makes it easier.
Good idea Bozzie, didn't know why i didn't think although i have done this for links :)
So mady,
just to build on bozzie's idea

"<table border=1><computedtext></table>"

an din the computedtext give the formual which he has given:

Nextlines := "<tr><td>"+NextAction+"</td>";
LastLines := "<td>"+ LastAction+"</td></tr>";
"<table>"+
@implode(LastLines;"")+
@implode(NextLines;"")




Partha
sorry didn't see bozzie has already given table tag inside the computed text :)

Thanks guys for the responses.

Initially i got idea to create documents and embed it on the form.

But, if I am using embedded view on the form, I can't have another embedded view (limitation in R5).To overcome this, we can use @dbLookups. But still we need to differentiate the alligning(as Last action have more data and NextActin will have none, these 2 should be in single row)

So, how to overcome this?

And RTF, Can be done or not? I went through the code. Looks promising.
But the user will edit the document and changes the value in LastAction field and then Saves the document.

In webQSave, I am running LS agent. So, we can do the changes in the backend. Can this be achieved through RTF?

Please advice.

And guys, my understanding of Notes is good. I got confidence assisting EE. Thanks a lot.

~madheeswar
Some things to help you decide how to solve this :

- you can show 2 (or more) embedded views on the web, using a iframe tag.  This asks for extra programming, though still doable.
- in R6, HTML tables are supported in the notes client too, so if you are planning on an upgrade, you could settle for solving the problem in the webinterface (computed text) and settling for the 'multivalue fields" in the notes client, until you upgrade.

I really wouldn't go for the RTF solution, unless you have a good reason too (eg. you need to export to Word, or you need to print, or you need compatibility with ancient notes clients (R4.x).  I did use the solution at MPartin Scott myself (works very good, but limited in layout possibilities), but this was still in R4.6.

cheers,

Tom
I agree with iframe use.
Currently I don't have any embedded views. So, I can try with single embedded view.

And how to make that embedded view to display alternate row colors, to differentiate each row? Will it be wise to open those documents or make it readable(i prefer this)?


I go for Embedded view for the time being. And we don't have any plans to upgrade.

thanks.
ASKER CERTIFIED SOLUTION
Avatar of Bozzie4
Bozzie4
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No, I am not getting any row colors.

It is just displaying as a HTMl view with first column as links. (consider it as Categorized and Not categorized situation)
The transformView(); call is in the onload event ?

If you  set the View setting to "html", you should also  build the table yourself.
That means you must put <tr><td>col1</td> in the first, <td>colX</td> in the following and <td>colLast</td></tr> in the last column.
You also need a <table id="myID"> at the top and a closing </table> at the bottom.

Then you can change the code to
var table = document.getElementbyId('myID')

cheers,

Tom
Why I need to use those <td> tags?
I did not used before.

Since this would be a Single Category Embedded view, how to make it to display alternate row colors.

can u be more elaborate since I did not worked on td tags before.

Thanks.
You only need the <td> tags if you would mark your embedded view as "Treat view contents as HTML" - you can do this, to be able to give your embedded view an id.

On the other hand, if you just embed a normal view, you'd have to guestimate what the value is to put here
var table = tableElements[tableElements.length - 1] ;

If your table is the 3rd in your document, you can put
var table = tableElements[2] ;

And you can debug the javascript code in your browser (Mozilla for instance), to see if the javascript executes correctly.

Tom

Ok. I will try and let you know.

but there are lots of tables on my form.

And one more question is:

Is it best to have responses to parent or create documents which will update doc id of parent document to the newly created documents?

Which is more helpful and why?

Think about both Web and Notes

Thanks
And as u people know, I need to send email if the last 3 updated value for NextAction is the same . this also should be considered for the above senario and which will best fit .

Thanks
The disadvantage of the responses approach is that you could come in a situation where also the replication conflicts of the main document appear in the view.
The advantage is that there is a very easy link, and you can make 1 view where all documents are displayed, including the responses.  If you don't need a view like that, you can just as well go for documents with a key (eg. the parentunid)

Tom
Tom,
I want to generate alternate row colors for the embedded view which is displayed as HTML(in embedded properties).

Since I have lots of tables on the form, I don't want to disturb them with the generic CSS.

This colors should apply only for this view.

I prefer the view to display as separate entries differentiated by alternate color and also a single white line horizontal and vertical.

Any ideas?

thank you.

~madheeswar
Put in the surrounding <table> tags :
<table id="MyViewTable">
$$ViewBody
</table>

Add custom css
<style>
#MyViewTable { border: 1px }
</style>



And change the function:

function transformView() {
var tableElements = document.getElementByID('MyViewTable') ;
var table = tableElements[tableElements.length - 1] ;
//table.width = '100%' ;
table.cellSpacing = '0' ;
table.border='1';

headers = table.getElementsByTagName("th") ;
for( i = 0; i < headers.length; i++) {
headers[i].bgColor = '#008DC8' ;
}

rows = table.getElementsByTagName("tr") ;
var counter = 0
for( i = 0; i < rows.length; i++) {
rows[i].bgColor = (i % 2 ? '#efefef' : '') ;

}
}
Tom,
I am using Embedded view. And I just created it on the form(not in a table).

So, where I need to place this code.

I have tried to keep the code in the below manner and of no use.
<table id="MyViewTable">
<style>
#MyViewTable { border: 1px }
embedded view
</style>
</table>


And the function in JS Header and calling this function in onload event of the form

And I get an error : object doesn't support this property or method
line:21

when I see the Source Code: the line 21 falls at function transformView() {

Any ideas Tom?

thanks
Sorry Tom,
this embedded view is created in Table for web.

For client, this is created on the form.

Thanks.
correct the tag order :

<table id="MyViewTable">
<style>
#MyViewTable { border: 1px }
</style>   <!-- <--- MOVE THIS TAG -->
embedded view
</table>

And I did put some errors in the javascript code, this works for me though :

function transformView() {
var table = document.getElementById('MyViewTable') ;
table.cellSpacing = '0' ;
table.border='1';

headers = table.getElementsByTagName("th") ;
for( i = 0; i < headers.length; i++) {
headers[i].bgColor = '#008DC8' ;
}

rows = table.getElementsByTagName("tr") ;
var counter = 0
for( i = 0; i < rows.length; i++) {
rows[i].bgColor = (i % 2 ? '#efefef' : '') ;

}
}

Tom,
Same problem.

The embedded view is not displaying anyvalues.

And the error is 'null' is null or not an object

Thanks Tom for your time.
Send me an email, I'll reply with a demo database where everything works as it should.

Tom
I am using R5.
I sent an email tom@gwbasics.com
Thanks
Tom,
thanks for the mail.

Can u please explain the JS Code and CSS. I understood a little from that code.

And it works now. I want to display my own colors instead of a white row. I have changed both colors and able to get only one row to change color.

This embedded view is in a Section. And when it is collapsed, I am getting Error on page.
here:  headers = table.getElementsByTagName("th") ;

When expanded there is no problem.

And the error msg is: 'null' is null or not an object

And final problems:
1) Need to change color for next row. Should not be white
2) When collapsed, error msg should not display.(Is it limitation?)

thanks

Tom,
I have placed the code outside of sectoin and it is working fine.

Thanks for your help. I am increasing points to 200 from 125.

-madheeswar
When in a collapsed section, the html objects don't exist.  If you want to hide it, it's better to use a dhtml approach , setting or unsetting the style visibility: hidden / normal for the table.
Another approach would be to first check for the existance of the #MyViewTable object, and only proceed if it exists.

var table = document.getElementById('MyViewTable') ;
if not( table==null) {
table.cellSpacing = '0' ;
...
}

I think you can set the default color by using the <style> tag too :

<style>
#MyViewTable { border: 1px;
background-color: white;
 
}
</style>   <!-- <--- MOVE THIS TAG -->
Tom,
Thanks.
'================
<style>
#MyViewTable { border: 1px;
background-color: blue;
 
}
</style>   <!-- <--- MOVE THIS TAG -->
'==================

this won't give alternate row colors. And if I use the same, I am getting white as background for the entire view.
So I palced background-color: white; in next line and I get entire table blue as background.

And
var table = document.getElementById('MyViewTable') ;
if not( table==null) {
table.cellSpacing = '0' ;
...
}


this gives syntax error. Something wrong.
thanks.
var table = document.getElementById('MyViewTable') ;
if (table!=null) {
table.cellSpacing = '0' ;
...
}

Setting the bgcolor in the table tag works, so I think I must be using the wrong css property ...

<table id="MyViewTable" bgcolor="red">
rows = table.getElementsByTagName("tr") ;
var counter = 0
for( i = 0; i < rows.length; i++) {
rows[i].bgColor = (i % 2 ? 'blue' : 'red') ;
}
}

And this works for alternating blue/red rows

cheers,

tom
that works great TOM.

Thanks for the help.

-madheeswar