Create an iconNote Document in a new database - xpages

This is a more explicite extension on my previous question.
From an button on an XPage I create a new database
targetDB = dir.createDatabase(fileName);
I then copy a bunch of stuff into the targetDB from the sourceDB. I then want to set the launch properties in the targetDB which is where the problem comes.
I know that I can get the iconNote = targetDB.getDocumentByID("FFFF0010") except there is no iconDoc in the target. Does anyone have a way to create this doc with the specific NoteID?
I tried copying the iconNote document from the sourceDB to the targetDB but that does not work. Changes the UNID and noteID. Can't find any database method to create an icon Note.
Found lots of stuff on how to change the settings in the iconNote, but nothing on how to create one if there is not one in the database.
Thanks to Jesse I took his code and changed it to SSJS and it works fine.
var dir:NotesDbDirectory = session.getDbDirectory("Development");
var newDB:NotesDatabase = dir.createDatabase("XPages/install/created.nsf");
var importer:NotesDxlImporter = session.createDxlImporter();
importer.setDesignImportOption(6);
var dxl:String = "<?xml version='1.0'?>\n" +
"<note default='true' class='icon'>\n" +
" <item name='$TITLE'>\n" +
" <text>Test Title</text>\n" +
" </item>\n" +
" <item name='$Flags'>\n" +
" <text>J7NZq?!</text>\n" +
" </item>\n" +
"</note>\n";
importer.importDxl(dxl, newDB);
var iconNote = newDB.getDocumentByID("FFFF0010");
iconNote.replaceItemValue("$DefaultXPage", "xpWFSDemo.xsp");
iconNote.replaceItemValue("$DefaultClientXPage", "xpWFSDemo.xsp");
iconNote.save();
dBar.info(iconNote.getItemValueString("$Flags"));

Something like this oughta do it:
DbDirectory dir = session.getDbDirectory(null);
Database newDB = dir.createDatabase("tests/created.nsf");
DxlImporter importer = session.createDxlImporter();
importer.setDesignImportOption(DxlImporter.DXLIMPORTOPTION_REPLACE_ELSE_CREATE);
String dxl = "<?xml version='1.0'?>\n" +
"<note default='true' class='icon'>\n" +
" <item name='$TITLE'>\n" +
" <text>Some DB Title</text>\n" +
" </item>\n" +
" <item name='$Flags'>\n" +
" <text>J7NZq?!</text>\n" +
" </item>\n" +
"</note>\n";
importer.importDxl(dxl, newDB);
That's with the two "open XPage" options set already - you could also include the two XPage name items the same way, and it may be a good idea to export the icon note from an existing DB (database.getDocumentByID("FFFF0010").generateXML()) and paste in the actual icon item as well, since this DXL will result in an icon-less database. Nonetheless, it seems to work in my testing as a basis.
And after that point, you'll be able to fetch the icon note using the usual "FFFF0010" pseudo-ID and replace item values the same way I mentioned before.

Related

Access field in a column in a Lotus Notes view

In Lotus Notes, I have view which has got a column say PolicyNum. Requirement is while double clicking on the document to open, which will open the attachment in the form in the view, it has to be validated against a computed field say SecureDoc which contains either Yes or No.
For client version this is easy as in the queryopen in the form it is validated and exited if the condition doesn't meet with proper messagebox.
But for the web version the column is appeared as a link and the messagebox has to appeared as alertbox in JS. In the PolicyNum column I have tried to use #GetField("SecureDoc") which will get the value of the field for that particular document.
Column Formula:
furl:="javascript:alert('Document not available');return false";
OpenDisp:="[" + PolicyNumber + "]";
secDoc:=#GetField("SecureDoc");
#If(att = "" ; OpenDoc ;secDoc="Yes";OpenDisp;OpenAttach)
Here OpenDoc and OpenAttach are different string which will open the document and attachment respectively depending on the att, which checks for the attachment.#GetField("SecureDoc") return "". So if I write #If(att = "" ; OpenDoc ;secDoc="";OpenDisp;OpenAttach) it is showing the alert box and is working fine.
So the requirement is to get the handle of the field value for the particular doc which is to be clicked on web and check for the condition.
Also webqueryopen is not working..
Note: On opening the document it is opening the attachment in the form and not the form itself.
Column Value :
view := "0";
att := #AttachmentNames;
WebName := #WebDbName ;
url := "'/" + WebName + "/" + view + "/" + #Text(#DocumentUniqueID) + "/$File/" + att + "?OpenElement'";
url := "window.open(" + url + ");" ;
url := #Implode(url; ";");
url := "javascript:" + url + " return false;\" href=\"javascript:void(0);";
furl:="javascript:alert('Document not available');return false";
OpenAttach := "[<TABLE><TR><TD NOWRAP><a target=_blank onClick=\"" + url + "\">" + PolicyNumber + "</a></TD></TR></TABLE>]";
OpenDoc := "[<TABLE><TR><TD NOWRAP>" + PolicyNumber + "</TD></TR></TABLE>]";
OpenDisp:="[<TABLE><TR><TD NOWRAP><a target=_blank onClick=\"" + furl + "\">" + PolicyNumber + "</a></TD></TR></TABLE>]";
secDoc:=#GetField("prevSecDoc");
#If(att = "" ; OpenDoc ;secDoc="Yes";OpenDisp;OpenAttach)
I have tried with both #If(att = "" ; OpenDoc ;secDoc="Yes";OpenDisp;OpenAttach) and #If(att = "" ; OpenDoc ;prevSecDoc="Yes";OpenDisp;OpenAttach) but it is not getting the value as "Yes". Though when I open the document through URL giving the docid it ha the value as "Yes"
Quick back to basics : a document is a record in a database, a form is, well, a form, which determines how data are input by the user and controls display.
Allow me to rephrase your question. If the document contains a field named "SecureDoc", and if said field holds the value "NO", then a click on the link must not open the document and present the user with a JavaScript alert.
One could question why display the document in the view in the first place, and then why have a link with no other effect than telling it has no effect.
OK, not my place to question the requirements.
My suggestion would be that the content of the column displayed for web access be a computed hyperlink :
href := #If( SecureDoc = "NO";
"javascript:alert('nope')";
"normal url for opening the doc"
);
"" + "the title of the doc or whatever" + ""

want to send data from one table to another on button click

In the below code i used label and text box to send data to sql . but instead of using label and textbox i want to send data from one table to another on button click . please let me know the shortest path .
SqlConnection con1 = new SqlConnection(strcon);
con1.Open();
SqlCommand com = new SqlCommand("update coupon set status =('" + Label2.Text + "'),macaddress =('" + mac.Text + "') where accode =('" + usename.Text + "')", con1);
com.ExecuteNonQuery();
con1.Close();
AddNewUserToNomadix();

Tracking document content changes

I'm trying to track the history of field values that are displayed in computed field as HTML. So far I got this:
var x = document1.getItemValue("category");
var html = "<table>";
for (i = 0 ; i < x.size(); i++){
html= html + "<tr><td>" + x + "</td></tr>";
html = html + "<tr><td>" + session.getEffectiveUserName() + "</td></tr>";
}
html = html + "</table>";
The code works ok, I get the value that I need and it gets displayed and if I edit the current document, the value changes via partial update that I have attached to the save button, but that's not the problem. The problem that I have is with saving it. I thought of creating an array and adding the value that changed but it will reset everything because of the script. Any suggestions how I can save that value or add it to the field? I was using Append ToTextList in forms, is there any way how to achieve that functionality in Xpages?
You can add a new value in a field in the querySave of the DominoDocument in XPages:
var x = document1.getItemValue("category");
x.add(myNewValue);
document1.replaceItemValue("category", x);
Chris Toohey just posted a blog article that seems to be what you're looking for.
http://www.dominoguru.com/page.xsp?id=thoughts_on_future_proofing_notesdata_for_application_development.html

XPages Extension Library Dialog control and updating "parent" document

I have an XPage with a Dialog control from the Extension Library.
The dialog works fine -- opens, does what it needs to do, however, when I try to update the "parent" document, it does not work.
I have the XPage data source as Domino Document called document1. I added this after reading:
When I save a document from an extension library dialog box some values are blank
<xp:this.data>
<xp:dominoDocument var="document1" formName="speakerReq"></xp:dominoDocument
</xp:this.data>
On the dialog control, I have a Search button which calls a servlet and returns JSON that is parsed and built into an HTML table. The first cell is a link which calls a function from a client side JavaScript library when it is clicked. The function is to update the "parent" document with values from the returned JSON as well as close the dialog.
It can call the function when I test with just an alert() statement in that function, however, when I try to update the "parent" document, it does not recognize that.
I have tried to pass the "document1" object but once I get to the dialog, it says it does not exist, so the link is failing.
Here is the code snippet where the link is built:
// Let's build the row...
cell = document.createElement("td");
resultLink = document.createElement("a");
resultLink.setAttribute("class", "linkText");
resultLink.setAttribute("href", "#");
resultLink.setAttribute("onclick", "javascript:updateDocument(document1, '" + bpName + "', '" + bpEmail + "', '" + bpPhone + "', '" + bpTitle + "', '" + bpCountry + "', '" + bpLoc + "');");
resultLink.appendChild(document.createTextNode(bpName));
cell.appendChild(resultLink);
row.appendChild(cell);
How do I get a handle on the document1 object on the client side so I can update those fields on the "parent" document as well as close the dialog?
Code:
function updateDocument(doc, name, email, phone, job, country, location) {
var thisField;
// Need to update the document with the selected values...
thisField = doc.getElementById("#{id:sr_Name1}");
thisField.value = name;
thisField = doc.getElementById("#{id:sr_Title1}");
thisField.value = email;
thisField = doc.getElementById("#{id:sr_Phone1}");
thisField.value = phone;
thisField = doc.getElementById("#{id:sr_Email1}");
thisField.value = job;
thisField = doc.getElementById("#{id:sr_Location1}");
thisField.value = location + " - " + country;
}
Thanks!
Seems you are mixing CSJS and SSJS up. The code snippet runs in the browser, but you try to execute server side code. This can't work. You need to post back your data to the server and handle the data there. The XPages Wiki has some ideas you might find useful.
Clarification:
Rule of thumb: anything that lands as JavaScript in your browser cannot have SSJS in it. So you can use anything DOM, but NO session, database, document1 etc. SSJS libraries are invisible to CSJS, so you can't call these methods. You can have a button in your page where you define both CSJS and SSJS. The client side would execute first and then do a refresh (partial or full).
Also your code above: getElementById is CSJS -> can't use that in a SSJS, while doc is as NotesDocumentDatasource -> doesn't have getElementById.
Furthermore: there is no "parent" element. The dialogbox is just another part of the local DOM (this is not NotesUIWorkspace.dialogbox). Check the XPagesWiki for samples

How do I filter a dojo grid on an xpage?

How do we filter the dojo grid (extlib component) that gets its data from the REST service component? I have the grid loaded with data from the view correctly from the REST service component. I also have on the xpage a dropdown where users can select a value that's a dbcolumn of one of the columns in the same view. I've tried setting the REST service keys value to viewScope.filterCat01 (which is the variable for the combo box), and I've also tried setting the filter in a button (BY is the field/column name) but nothing seems to filter it. Any ideas? In the button when I check grid properties, it does work, so I know the grid object is valid - but the filter just doesn't seem to be doing anything. I've also tried doing a grid._refresh() as well as setting the Keys in the REST service component with no luck. Is there a special way to trigger the filter?
var filterValue = XSP.getElementById("#{id:comboBox2}").value;
var grid = dijit.byId("#{id:djxDataGrid1}");
grid.filter({ By: filterValue});
This is definitely one of those things that you need to piece together a thousand cryptic clues to work it out (Domino - never!). Anyway, I had to work this one out last year. Here's an example 'search' button:
var searchText = dojo.byId('#{id:searchText}').value.replace(/"/g, '|"');
if (searchText) {
var ftSearchText = '[Title] CONTAINS "' + searchText + '" OR [Description] CONTAINS "' + searchText + '" OR [URL] CONTAINS "' + searchText + '"';
dijit.byId('#{id:grid}').filter('?search=(' + ftSearchText + ')', false);
} else {
dojo.byId('#{id:reset}').click();
}
As you can see, it's doing an ft search when a filter is applied. The key is to put "?search=" on to the beginning of the filter string.
and here's the 'reset' button example:
dojo.byId('#{id:searchText}').value="";
var grid = dijit.byId('#{id:grid}');
grid.filter("",true);
grid.store.close();
grid._refresh();
This was developed with 8.5.2. There might be some cleaner ways to do things in 8.5.3 with dojo 1.6.1.
Enjoy!

Resources