I am trying to create an action that opens a tab, inserts an uploaded file's external URL into the tab, and navigates to that URL just like as if a user clicked the Files button and then clicked one of the File's titles and it opened up the tab with the contents of the file.
Here is the code I used to get the External Link. Please note that I have the FileID stored as an extension column in the InventoryItem table for this example:
PXView item = Base.Views["Item"];
InventoryItem item = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD,
Equal<Current<InventoryItem.inventoryCD>>>>
.Select(Base, Base.Views["Item"].Cache.Current);
InventoryItemExt itemext = item.Cache.GetExtension<InventoryItemExt>(item);
UploadFileWithIDSelector fileInfo = PXSelect<UploadFileWithIDSelector,
Where<UploadFileWithIDSelector.fileID,
Equal<Current<PX.Objects.IN.InventoryItemExt.usrDefaultSpecID>>>
.Select(Base, itemext.UsrDefaultSpecID);
I then try to execute the following code to open the page using the ExternalLink:
throw new PXRedirectToUrlException(fileInfo.ExternalLink, "");
This results in the following error:
Object reference not set to an instance of an object.
Is the DAC unable to directly get the external link? Is there any way to fix this so it retrieves the external link? Is there another (possibly simpler) way to retrieve the external link of an uploaded file?
Thanks
You should be able to redirect to the file with this syntax:
throw new PXRedirectToUrlException(PXRedirectToFileException.BuildUrl(fileInfo.fileID), "");
Consider using this syntax to redirect since you don't need a message:
throw new PXRedirectToFileException(fileInfo.fileID, true);
Related
My issue is like that:
I have the inventory detail sub record window, I did an iframe to change the view there and replaced it with my suitelet, in my suitelet I upload a file or simple text and then I want to use that values to change the record that I came from (the record is on creating not edit mode)
is it possible?
You can add a client script for your Suitelet. like below:
// Creating the form.
var form = serverWidget.createForm({
title: 'Suitelet Title',
hideNavBar: false
});
//Adding the Client script (I used a relative path)
form.clientScriptModulePath = './YourClientScript.js';
In Stock Items screen we created a button and on this button click we are downloading some certificates from third party and storing into files section. we also created a button GET CERTIFICATE on this button action, we want user to redirect to GetFile.ashx screen. Like how standard Acumatica will take us when we click on link from Files popup.
We are using 2019 R1, here is my code sample:
throw new PXRedirectToUrlException(string.Format("~/Frames/GetFile.ashx?fileID={0}", fileId), "Certificate") { Mode = PXBaseRedirectException.WindowMode.NewWindow };
It looks there is a good example of this found in SOShipmentEntry (PrintCarrierLabels method) if you have the fileid already:
string targetUrl = PXRedirectToFileException.BuildUrl(mergedFile.UID);
throw new PXRedirectToUrlException(targetUrl, "Print Labels");
You can also use PXRedirectToFileException if you have the FileInfo object:
throw new PXRedirectToFileException(file, true);
These might open/download the file as I am not sure of the results. These are examples I found in the Acumatica source for working with fileid.
If you really want the user to download the file this is a good post: How to add Button for downloading excel file in Acumatica
I am using JDeveloper 11.1.2.3.0
I have to show a popup by clicking a link that is located in the page template. For this I created a popup within the pageTemplate then inserted a dialogBox and within the dialog box I dragged and dropped my VO from the DataControl panel and inserted it as an ADF form. The problem is that when I run and click the link (that contains the "ShowPopupBehavior") I am getting this error:
//C:/Oracle/Middleware/jdeveloper/jdev/system11.1.2.3.39.62.76.1/MyNew/ViewControllerWebApp.war/WEB-INF/templates/myTemplates.jsf #58,118 value="#{bindings.TypeName.inputValue}": Target Unreachable, 'TypeName' returned null
ADF_FACES-60097:For more information, please see the server's error log for an entry beginning with: ADF_FACES-60096:Server Exception during PPR, #2
This happens for every View that I can insert here. Is this comming because I am not allowed to insert ADF forms within the page template?
If so please give me a hint to achieve what I explained in the first sentence.
I just figured out the solution to this problem. Each page has its own bindings, so a page that uses the templates (or if want to use bindings from other pages) has to declare that page in the Executables section of the page Bindings. The new executable should have the ID of the page (of the template in this case) and the path of the page. Then the bindings of the template can be accessed as explained here:
public String cb1_action() {
BindingContext bctx = BindingContext.getCurrent();
DCBindingContainer bindings =
(DCBindingContainer)bctx.getCurrentBindingsEntry();
//access the page template Pagedef file reference in the
//Executable section of the consumer page's Pagedef file
DCBindingContainer templateBinding =
(DCBindingContainer)bindings.get("ptb1");
//get the MethodBinding
OperationBinding printMethod =
(OperationBinding)templateBinding .get("printThis");
//invoke the print method exposed on the template's PageDef file
printMethod.getParamsMap().put("message","Hello World");
printMethod.execute();
return null;
}
https://blogs.oracle.com/jdevotnharvest/entry/how_to_invoke_adf_bindings
ps: Pay attention not to bind the value of the template in your page ex: value="#{bindings.ptb1}" - it is a bit strange but in this case you will not get the page bindings and will get only the template ones.
The value property containing #{bindings.ptb1} should be removed from the pageTemplate tag but the ptb1 reference has to be in the pages PageDef file.
I have a document that I want to create a new version/copy of, so I am trying to do server-side javascript to
Create a new document
copy all items from the current document
open the new document that I have created, without saving it
I am not able to open the newly created document, is this possible?
code I am using is:
var viewPanel=getComponent("viewPanel1");get the componet of viewPanel
var docIDArray=viewPanel.getSelectedIds(); get the array of document ids
for(i=0;i < docIDArray.length; i++){
var docId=docIDArray[i];
var doc=database.getDocumentByID(docId);
var newDoc = database.CreateDocument
doc.CopyAllItems (newDoc)
var docUNID = newDoc.getUniversalID ()
// need something here to open copied document
}
You need to store the IDs in the session scope and then open the page and do the copy inside in one of the data source events:
var viewPanel=getComponent("viewPanel1");get the componet of viewPanel
var docIDArray=viewPanel.getSelectedIds(); get the array of document ids
sessionScope.alltheDocs = docIDArray;
then open the page where you want to have the new document. Inside that page you need to have a repeat control that matches the element count of alltheDocs. I probably would design it using a DojoTab container (one tab per document). Inside the repeat place a panel with a data source (or a custom control). Then in the queryNewDocument event you copy the fields using the variable name of your datasource.
You could save these docs, then show them and add them to a deletion queue by marking a field on those docs. On save remove them from deletion queue as a work around possibly.
1) Do not store Notes object to scope lasting longer than request.
2) If XPage has to inherit some values, it needs to read them from some source.
3) You can not inherit data from Notes document - according to (1) in memory object must not be stored in sessionScope (simplest way to pass objects between two pages), and you can not retrieve it by UNID/key (it is not saved, as requested).
So, (possibly) the only option is:
Make copy of source document - copy every field you are interested in into Map[String,Object]. Fields must be converted into "raw" objects String, Double, Date (java, not Notes) or their vectors for multivalues. You must not copy special (Notes objects) fields - names, dates, rich text! Names can be converted to strings, Dates can be retrieved as Java dates, rich text might be treated as MIME (String) (but with possible loss of formatting). I think you don't want to pass attachments.
In target XPage, define queryNewDocument event to lookup and initialize fields from this Map object. Delete the sessionScope object to prevent duplicates.
I needed very similar thing in my application. I have XPage with a source document opened in read mode. There is a button that creates a new document and set few values (using the source document). I wanted the XPage to open this new document in Edit mode after it was created.
Note: I could not use redirect with URL parametr action as I needed to open it in a same XPage and preserve a view scope variables and beans.
Solution:
Add View Scope variables NewDocAction and documentId (on button click),
Partial refresh of XPage (on button)
Compute document data source using viewScope variable documentId
Check presence of View Scope variable NewDocAction (in onClienLoad event)
javascript code in the button:
var travelDoc = xpBean.createTravelDoc(requestDoc);
if (travelDoc != null){
viewScope.put("content","travelForm"); //to render proper CC on XPage
viewScope.put("documentId", travelDoc.getUniversalID());
viewScope.put("NewDocAction", "ToEditMode");
}
javascript code in a onClientLoad event of a travelForm custom control:
if (viewScope.containsKey("NewDocAction") && viewScope.get("NewDocAction").equals("ToEditMode")){
context.setDocumentMode("travelDoc","edit");
viewScope.remove("NewDocAction");
}
I have an aspx page with inline code in which I am trying to update the view programmatically by setting view's Query property to my CAML query. When I run with administrator user everything works perfect view get updated successfully but when I logged in with a user who belongs to visitor group and having read only access then I get an error on view.Update() line saying that:
"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack"
I have already try to run this code block with ElevatedPrivileges but not get any luck...(
following is my code which make you more clear:
SPUserToken token = CurrentSite.SystemAccount.UserToken;
using (SPSite st=new SPSite(SPContext.Current.Web.Url,token))
{
st.AllowUnsafeUpdates = true;
using (SPWeb wb=st.OpenWeb())
{
wb.AllowUnsafeUpdates = true;
vwSearchResult.Query = Query;
vwSearchResult.Update();
}
}
What you are doing here, is modifying the definition of the view for ALL users of the website, not only the current rendering instance of the page. This is why simple visitors cannot change it (they do not have such permission in the web)
If you want to do something, using the "SystemAccount" token, you have not only to do the "using SPSite, using SPWeb", but also find the list and the view using the "strong" SPWeb objects
Instead of modifying a view definition at runtime, you might want to consider using ListViewByQuery class http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.listviewbyquery.aspx