On save of a document I'm running SSJS that is doing a .save() and then I am wanting to include the document link (URL) in the body of a notification email that gets sent by using context.getUrl().
This works for documents that are already saved because it has the doc id in the URL when doc gets opened, but not for new docs. Is there a way I can accomplish this for new documents that do not have their ID yet?
You have to construct the URL yourself since (as you already know) the context.getUrl() method can not be used.
So after your .save() you could do something like the following:
var docUrl = context.getUrl().toString().split(view.getPageName())[0] + "/" + database.getFilePath() + view.getPageName() + "?action=openDocument&documentId=" + document.getNoteID();
The context.getUrl().toString().split(view.getPageName())[0] part should give you the hostname and database filepath according to David Leedys xpagescheatsheet.com URL test. I then add the current XPage name and the openDocument and docid parameters.
Another possibility: if you have a form behind the document and the property "open XPages instead" you can use the http://server/database.nsf/0/universalid syntax. When you have an unique identifier in your document you also can use a view sorted by that identifier and use http://server/database.nsf/sortedview/sortkey. With the sorted view you could predict the URL before saving.
Related
I would like to see if a document exists in the database that has the name field "name" set to "a name" before allowing a new document to be added to the database.
I this possible in CouchDB using update handlers (inside design documents)?
Seems you are looking for a unique constraint in CouchDB. The only unique constraint supported by CouchDB is based on the document ID.
You should include your "name" attribute value into the document ID if you would like to have the document unicity based on it.
Validate document update functions defined in desing documents can only use the data of the document being created/updated/deleted, it can no use data from other documents in the database.
Yo can find a similar question here.
This is not widely known, but _update endpoint allowed to return a doc with _id prop different from requested. It means, in your case, you need to have an unique document say _id:"doc-name", which will serve as a constraint.
Then you call smth like POST _design/whatever/_update/saveDependentDoc/doc-name, providing new doc with different _id as a request body.
Your _update function will effectively receive two docs as an input (or null and newDoc if constraint doc is missing). The function then decides what should it do: return received doc to persist it, or return nothing.
The solution isn’t a full answer to your question, however it might be helpful in some cases.
This trick only works for updating existing docs if you know revision, for sure.
There is a viewPanel1 that lists some docs. and having also the var property set to rowData.
How can I easily get the datasource name for a clickable doc / row ? Is there a 'quick' method something like:
rowData.getDocument()./* getting the datasource name */ ?
Thanks for your time.
You can not get the data source name for the document but rather the form name. Based on the form name you can then decide on an action for that particular document.
Use the following:
rowData.getDocument().getItemValueString("Form")
I have a process on the beforePageLoads that executes if it is a newDocument. It grabs a profile docuemnt that contains a number of fields that I need to copy into the XPage that is being loaded. I use the following code:
var iCol:Array = pDoc.getItems()
for(var i=0; i<iCol.length; i++){
var item:NotesItem = iCol[i];
var iName:String = item.getName();
if (#Left(iName, 2) == "AC" ){
iCol[i].copyItemToDocument(doc,"");
}
item.recycle()
} // for loop
where pDoc is the profile document and doc is backend document obtained by var doc = document1.getDocument(). I can then use the copyItemTODocument method and this works real well except I need to refresh the dataSource from the backend document. I can do this from a button and do a partial refresh but that is not an option in a production situation. I have tried various refresh options (suggested in this forum) but none of them get the job done. I can copy the values from the profile document fields to a filed in the datasource but this gets really messy because of data types. I believe my refresh problem is related to updating the doc not document1 in my code. Is there a way to refresh document1 from the backend document?
Does this help ..
http://xpagesblog.com/XPagesHome.nsf/Entry.xsp?documentId=84329CA285163DDF852578CB00669143
it hints at two things whcih may be osf use :
"It appears that during the initial PageLoad events the existing data is transferred from the NotesDocument to the NotesXspDocument. Only those fields bound to the NotesXspDocument (on XPage or CC) are transferred. "
and in the comments section:
"Another way of getting data from the XspDocument to the NotesDocument without a save, is to use document1.getDocument(true) which basically re-syncs the data between the two objects.
I don't have time to experiment I'm afraid but it looks like this is along the right lines, espcially the second part.
Doug
On SalesForce ,
I've got a word document as an attachment of a custom object, i can get it as blob by selecting the body of the attachment with a SOQL query :
Attachment att = [ SELECT Body FROM Attachment WHERE PARENTID = '**' and ContentType='application/msword'] ;
Blob b = att.body ;
I tried to use the b.toString() function to have the content, but it didn't work.So is there any other way to convert the blob into a string that represent the text written in my word document.
thanks
Document bodies are saved as Blobs and are base64Encoded. Please use the EncodingUtil class and bas64Encode/base64Decode methods to achieve the desired results.
Documentation: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_encodingUtil.htm
What exactly are you trying to achieve with this?
If you are trying to display the doc. content and let the user edit/save it. This is not possible unless ActiveX controls are used which is another different level.
Please post the code if any coding help is required!
The b.toString() method should return a string of the blob. But keep in mind that it isn't translating the proprietary format of the word document into plain text. It's still going to be a string with some ugliness because it represents the word document format and not the text you would see when viewing from word.
I'm learning couchapp and it looks pretty easy to query database items.
But I have items with attachments, and I'd like to add hyperlinks to the attachments:
{{description}}
I can get id, attachment and description setup properly, but how do I get the current database name (or URL) from within a couchapp javascript function?
If you don't want to use relative urls, you can fetch the db name in following way:
var dbname = unescape(document.location.href).split('/')[2]
since your href looks like: http://host:port/dbname/doc...
This is also the code jquery.couch.app.js uses. So if you are using it, it's available for you in initialization code:
$.couch.app(function(app) { alert(app.db.name); });