xpages getting the URL after saving a new created doc - xpages

I'm looking to get the URLlink for a document. For the existing documents ( which are already saved and when I open them - I get the url with the UNID ) , it's OK, my problem is when I want to get the URL for a new created document - i don't get the UNID inside the URL. ( only, eg: http://myserver/ournsf/doc.xsp?action=newDocument, without the UNID )
My code is something like this:
if(docSource.isNewNote()){
docSource.save();
}
empbody.appendText(context.getUrl().toString())
Thanks for your time!

context.getUrl() gives you only the current URL. It doesn't contain the documentId because you create a new document in your case.
You are looking for an URL that will open current document with current XPage. You can get it with:
var thisdoc = docSource.getDocument(true);
var url = facesContext.getExternalContext().getRequest().getRequestURL().toString() +
"?action=editDocument&documentId=" + thisdoc.getUniversalID());

You can get the url of a new created document with:
document1.getDocument().getUniversalID()
Here document1 is the datasource name of your document.
If you want to redirect to the new created document after a save, you can use this code in a navigation rule or add the following XML:
<xp:this.navigationRules>
<xp:navigationRule outcome="xsp-success">
<xp:this.viewId><![CDATA[#{javascript:return "XPageName?documentId="+document1.getDocument().getUniversalID()+"&action=editDocument"}]]>
</xp:this.viewId>
</xp:navigationRule>
</xp:this.navigationRules>
Where XPageName is the name of the XPage.

You could use the postSaveDocument event of your datasource to calc the URL from the UNID like
var url = "page.xsp?action=openDocument&documentId="+document1.getDocument().getUniversalID();
document1.setValue("url", url);
document1.save();

Related

Getting document attachments using Kentico API

I created book store site on Kentico i used only their adminstration and display the data from my website using Kentico API's but am strugled in getting attachment files related to specific document i've got document data with no problem using
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
var documents = tree.SelectNodes("CMS.Product");
need also to get related attachment files like book PDFs.. i've tried to use
DocumentAttachment
AttachmentInfo
AttachmentInfoProvider
classes but i couldn't get the data .. I would appreciate if any one help me in that.
Actually am searching about something like GetAttachment().Where("AttachmentFile","Ënglish File")
You can filter the returned attachments based on their values in columns (CMS_Attachment table) by using a code like this:
var attachment = AttachmentInfoProvider.GetAttachments()
.WhereEquals("AttachmentName", "Englishfile")
.And()
.WhereEquals("AttachmentExtension", "jpg")
.TopN(1)
.FirstOrDefault();
if (attachment != null)
{
// attachment was found
}
This code will get one .jpg file where attachment name equals to "EnglishFile"
Solved after using something like
var Attachment = AttachmentInfoProvider.GetAttachments(226, true);
This is from Kentico documentation. This example shows how to add an attachment and modify its metadata. You can ignore that part.You will have to make it generic to work for all examples.
Kentico 9 API Links
// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
// Gets a page
TreeNode page = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/Articles", "en-us");
if (page != null)
{
// Gets an attachment by file name
AttachmentInfo attachment = DocumentHelper.GetAttachment(page, "file.png", tree);
// Edits the attachment's metadata (name, title and description)
attachment.AttachmentName += " - modified";
attachment.AttachmentTitle = "Attachment title";
attachment.AttachmentDescription = "Attachment description.";
// Ensures that the attachment can be updated without supplying its binary data
attachment.AllowPartialUpdate = true;
// Saves the modified attachment into the database
AttachmentInfoProvider.SetAttachmentInfo(attachment);
}

Remove All Attachments from document xpages

In my document i have multiple "Body" field which contains Rich-Text data as well as attachment files which is of type (Data Type: MIME Part).
My purpose is to only delete the attachment files from my document. I tried this,
if (document1.getAttachmentList("body").isEmpty()) {
requestScope.alist = "No attachments in body";
} else {
document1.removeAllAttachments("body");
document1.save();
requestScope.alist = "All attachments removed from body";
}
where document1 is my data source name, by this code it works properly.
But, i want to retrieve document by
var doc:NotesDocument = database.getDocumentByUNID(context.getUrlParameter("documentId"));
where it does not works.
I had even tried by this code,
var doc3:NotesDocument = database.getDocumentByUNID(context.getUrlParameter("documentId"));
var item:NotesItem =doc3.getFirstItem("$FILE");
item.remove();
doc3.save();
But, here problem is that it also deleting rich text data from document.
Is there any other solution can help me out.
Thanks in advance.
In the first working code you have a the NotesXSPDocument, but in the second example you have the NotesDocument.
may be it is an idea to convert the NotesDocument to a NotesXSPDocument so you can use the first example
To convert it in SSJS this example may help you
https://openntf.org/XSnippets.nsf/snippet.xsp?id=wrap-notesdocument-into-notesxspdocument
What is the difference between the "NotesXspDocument" and "NotesDocument" class in XPages
https://www-10.lotus.com/ldd/ddwiki.nsf/dx/xpages-notesxspdocument-vs-notesdocument.htm

Get view name in xpages view control

I'm using a view control to display a notes view. We are also using a search function, to search the first column of each view. As we want to save the search parameter a user has entered, we've created a bean saving the search key for each user.
To save the seach key, we are using this code in the data > keys property of a view control:
var dbName:String = database.getFilePath();
var viewName:String = "vwCurrentRequests";
var searchValue:String = searchUserBean.getSearchValue(dbName+viewName);
if(searchValue.isEmpty() || searchValue==null) {
return "";
} else {
return searchValue;
}
But we always have to define the viewName value for each view. So the question is: How can we get the view name of the current view?
You can access the name of the view with this SSJS code:
getComponent("viewPanel1").getData().getViewName()
viewPanel1 is the id of your view panel.
EDIT:
As Frantisek Kossuth wrote, you can use the this keyword instead of the getComponent.
this.getData().getViewName()

Passing value of query string in multiple views MVC3

I am successfully redirecting user after Login to a page called CustomerStart. After that query string (url) looks fine with the ssn like this
localhost:1234/CustomerStart?ssn=850406-0297
I am doing this by writing this
return RedirectToAction("Index", "CustomerStart", new {ssn = model.ssn});
But when I click a button which has been defined in the _layout like this,
<li>#Html.ActionLink("CustomerStart","Index", "CustomerStart")</li>
my query string gets empty.
I want to keep my customer to be in the same CustomerStart page both after login or if they click the CustomerStart button.
I also want to send my customer in different views when they click any of the button under the above mentioned one.
like this,
<li>#Html.ActionLink("CustomerStart","Index", "CustomerStart")</li>
<li>#Html.ActionLink("Bill","Index", "Bill")</li>
So, i need to grab the value from the query string always. But I dont know how?
I am new in MVC3 and I am totally lost.
try
<li>#Html.ActionLink("CustomerStart","Index", "CustomerStart",
new { ssn=Request.QueryString["ssn"]},
null)
</li>
<li>#Html.ActionLink("Bill","Index", "Bill",
new { ssn=Request.QueryString["ssn"]},
null)
</li>

Sharepoint List redirect with new id

I have a list within Sharepoint, using a custom new form I have added a custom list form control ("New item form" for the list) and changed the SaveButton to a standard input HTML button, and added an 'onclick' event that is as follows:
onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={NewFormWizard2.aspx?id=}')}"
This works as in saves the data and redirects to the NewFormWizard2.aspx?id= page.
How do I get the ID of the created item to be passed to the redirected page?
Thus once the form is completed it would redirect to NewFormWizard2.aspx?id=23
jtherkel was close, but was missing a '}' on the end of the redirect url. I used an extra concat below
<input type="button" value="Submit" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={lists/MyListName/DispForm.aspx?ID=',/dsQueryResponse/Rows/Row/#ID,'}'))}" />
I am not sure where the ID will exist on the page you host the Javascript from. Does it appear in the querystring or on a field on the page?
There is nothing in the request or response that will identify the item. I have had this issue when doing some web loadtesting.
I can only suggest that your create the item using the webservices as that at gives you some return xml.
This answer does not solve the "new form" issue, but it might help others with the syntax for screens that contain existing list items.
I tested this quickly in my SharePoint (MOSS 2007) environment.
onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={NewFormWizard2.aspx?id=',/dsQueryResponse/Rows/Row/#ID))}"
The concat syntax is an XSLT instruction that tells the processor to combine the values enclosed in single quotes. I adapted this answer from info I found here.
Loading Values in a Custom List Form
http://wssdevelopment.blogspot.com/2007_04_01_archive.html
I hope this would be helpfull:
1- In SharePoint Designer create new page, call it for example "LastItem.aspx" and place a dataview on it with a single form view for the destination list item.
2-Limit paging to just one record, set the sorting by ID and descending and filter the list to just show item which is created by [current user].
3-Now you do not need to pass any query string to this page. just replace the default "OK" button in NewForm.aspx of the list with a standard HTML input button and add this to its definition "onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={LastItem.aspx}". After submitting a new item to list you will be redirected to an edit view of the created item.
You can do the same for save button in LastItem.aspx to redirect to some other page after clicking on save button.
found an approach using pure javascript (JQuery) and the SPAPI code from http://darrenjohnstone.net/.
The list contains two fields, title and BodyCopy
I've thewn created a form that asks for a title and a question, both text fields, then the submit button calls the following function: (note that ServerAddress and LIST_question need to be updated to your own details).
The function then uploads the details using the SOAP service within LISTS.ASMX and using the response gets the ID of the new item and redirects the page.
var LIST_question = '{xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}';
var ServerAddress = 'http://xxx/';
function submitQuestion()
{
var title = new String($("#title").val());
var t = new String($("#question").val());
t=t.trim();
if(t=="")
return;
title=title.trim();
if(title=="")
return;
var lists = new SPAPI_Lists(ServerAddress) ;
//
var newItem = { Title : title, BodyCopy : t};
var items = lists.quickAddListItem(LIST_question, newItem);
var id=-1;
if (items.status == 200)
{
var rows = items.responseXML.getElementsByTagName('z:row');
if(rows.length ==1)
{
var r = rows[0];
var id = r.getAttribute('ows_ID');
window.location.href='DispForm.aspx?ID='+id;
}
else
{
alert("Error: No row added");
}
}
else
{
alert('There was an error: ' + items.statusText);
return;
}
}
You can achieve this using JavaScript http://www.sharepointdrive.com/blog/Lists/Posts/Post.aspx?ID=9

Resources