How to use PXRedirectToUrlException in Acumatica with two URLs - acumatica

The sample code below will only create a new tab for the first URL. The goal is to have Acumatica create two separate tabs for two different URLs.
int countFirst = 3;
int countSecond = 4;
if(countFirst > 0) {
throw new PXRedirectToUrlException(firstUrl, PXBaseRedirectException.WindowMode.New, "First");
}
if(countSecond > 0) {
throw new PXRedirectToUrlException(secondUrl, PXBaseRedirectException.WindowMode.New, "Second");
}

Being that these are exceptions, the second line of code will not be executed. Perhaps you can try catching the first and if that does not work then maybe try pushing both through a PXLongOperation to get each into its own thread.

Related

How do I transfer rich text attachments from one document to another

I have 2 documents which are supposed work in such a way to be able to transfer files between them. However, it doesn't work. The exception I get is Exception occurred calling method NotesDocument.save() Notes error: One or more of the source document's attachment are missing. Run Fixup to delete the document in the source database. This happens after I try to call save() function on the document to which I've just transfered files from the first.
The functions are below:
function transferFiles(docToGetFrom, docToTransferTo, fileFieldFromFirstName, fileFieldFromSecondName)
{
var rit1:NotesRichTextItem = getFirstNotesRichTextItem(docToGetFrom, fileFieldFromFirstName);
docToTransferTo.copyItem(rit1, fileFieldFromSecondName);
deleteAllFilesFromDocument(docToGetFrom, fileFieldFromFirstName);
docToTransferTo.save();
}
function getFirstNotesRichTextItem(documentToGetFrom, fileFieldName)
{
if (documentToGetFrom == null)
{
return(null);
}
if (!documentToGetFrom.hasItem(fileFieldName))
{
return(null);
}
var rit1:NotesRichTextItem = documentToGetFrom.getFirstItem(fileFieldName);
return rit1;
}
function deleteAllFilesFromDocument(documentToDeleteFrom, fileFieldName)
{
var arr = getAllEmbeddedObjects(documentToDeleteFrom, fileFieldName);
for(var i = 0; i < arr.length; i++)
{
arr[i].remove();
}
documentToDeleteFrom.save();
}
function getAllEmbeddedObjects(documentToGetFrom, fileFieldName)
{
var rit1:NotesRichTextItem = getFirstNotesRichTextItem(documentToGetFrom, fileFieldName);
if (rit1 == null)
{
return(null);
}
try
{
var arr=rit1.getEmbeddedObjects();
return arr;
}
catch(e)
{
return(null);
}
}
According to plain logic, I need to do the following in order to make it work:
Get attachments from the document A
Copy them to the document B
Remove attachments from the document A
Call save() on A
Call save() on B
I did exactly the same, but nevertheless get this nasty exception. Also, I've tried to solve the problem by setting OLEDisableFX to 1, but with no luck. I assume that something must be wrong with the method copyItem() (I guess it can only work properly with simple datatypes). What's the problem? Thanks in advance.
You'll probably need to detach the attachment from the source document and attach it to the target document. See the NotesEmbeddedObject class for examples.
Use the CopyItemToDocument method of the NotesItem class. The following is some code I used in a LotusScript agent but the CopyItemToDocument method is also available in Java and SSJS.
If doc.Hasitem("RTF1") Then
Set item = Nothing
Set item = doc.getFirstItem("RTF1")
Call item.Copyitemtodocument(targetdoc, "targetRTF")
Call item.Remove()
End If

Unable to Invoke Inserted Javascript Fragment

I am attempting to insert a Javascript fragment into a webpage and then invoke it using blue prism. The purpose of this is to analyse what elements are returned from a search to determine where to go next in the overall process flow.
I have tested the Javascript code on the intended website using the IE 11 developer console and it works without issue. The code is below in case it is useful.
function includes(stringToCheck, CharacterToSearchFor)
{
var found = new Boolean();
var splitString = stringToCheck.split("");
for (var index = 0; index < splitString.length; index++)
{
if(splitString[index] == CharacterToSearchFor)
{
return true;
}
}
return false;
}
function getPartners() //declare a function which can be called from BP. once called all code within the enclosing {} will be run
{
var searchResults = document.getElementsByClassName("findASolicitorListItem"); //search the web page for all elements with a specific tag and store them in a variable called searchResults.
if(searchResults.length == 0) // If the number
{
alert( "No Solicitors were found.");
}else if(searchResults.length == 1)
{
var innerSearchResults = searchResults[0].getElementsByTagName("span");
for(i = 0; i < innerSearchResults.length; i++)
{
var spanText = innerSearchResults[i].innerText.toString();
if((spanText != ""))
{
if(!includes(spanText, "|"))
{
alert("One Solicitor found. " + spanText);
}
}
}
}else if (searchResults.length > 1)
{
alert( "More than one solicitor was found. Manual Checking required.");
}
}
This is stored in a data item and is passed into the Navigate stage (Insert Javascript Fragment) parameter.
PrintScreen of Insert Javascript Fragment stage
When this stage is ran it successfully injects the Javascript functions into the webpage.
I then try and invoke this inserted javascript fragment
Printscreen of Invoke Javascript Function stage
When this stage runs I get the following error message raised by Blue Prism.
Internal : Failed to perform step 1 in Navigate Stage 'Analyse Result' on page 'Analyse Search Results' - Failed while invoking javascript method:Exception from HRESULT: 0x80020101-> at mshtml.HTMLWindow2Class.IHTMLWindow2_execScript(String code, String language)
at BluePrism.ApplicationManager.HTML.clsHTMLDocument.InvokeJavascriptMethod(String methodname, String jsonargs, Object& retval, String& sErr)
I have searched for this error code and found this answer which indicates there is a problem with the code however I can manually run this code just fine.
Does anyone have any experience with using these methods in BluePrism or have seen this error message before who can help me resolve?
I was actually never able to get Invoke Function working reliably with parameters, I always use Insert Fragment for everything, invoking included.
If you insert this function as a fragment...
function sayHello(name)
{
alert("Hello " + name + "!");
}
...to invoke it you just insert this as another fragment:
sayHello("World");
Tadaa!
As a side note, I am not sure which element in Application Modeler you are using for fragment insertion, but it seems like you are using the root (application) node. I had better experience with inserting the fragment to a dedicated HTML BODY element, for some reason the performance is much greater.
To invoke function by action "Invoke Javascript function", in Arguments field you should put arguments in JSON syntax. If there is no argument you put "[{}]".
On the above Marek's example the function should look:
function sayHello(name)
{
alert("Hello " + name.name + "!");
}
and arguments: "[{'name':'world'}]".

How to prevent global event handlers from firing caused by an API call

I have a custom module that uses Kentico API (DocumentHelper) to update certain fields of my document and then publish but I do not want it to trigger the event handlers that are linked to my document page type. I tried adding comments to .Publish("admin_edit") hoping that I can catch it from the WorkflowEventargs parameter but the VersionComment property always return null. Is there a way to accomplish this in Kentico?
update field:
var document = DocumentHelper.GetDocument(documentID, tree);
var workflowManager = WorkflowManager.GetInstance(tree);
var workflow = workflowManager.GetNodeWorkflow(document);
if (workflow != null)
{
document.CheckOut();
document.SetValue("SomeFIeld", "some value");
document.Update(true);
document.CheckIn();
document.Publish("admin_edit");
}
event handler:
public override void Init()
{
WorkflowEvents.Publish.After += Publish_After;
}
private void Publish_After(object sender, WorkflowEventArgs e)
{
if (!string.IsNullOrEmpty(e.VersionComment) &&
e.VersionComment.Contains("admin_edit"))
return;
}
You always get null for Version information, because that is related to the 'Page versioning' events, specially for 'SaveVersion'. You can find more about that on this link. If you expand 'Properties' you will see which properties are populated for the specific event. In your case, you can try something like this, to add your message for last version and then check for that comment on 'Publish_After' event, see code bellow:
var document = DocumentHelper.GetDocument(documentID, tree);
var workflowManager = WorkflowManager.GetInstance(tree);
var workflow = workflowManager.GetNodeWorkflow(document);
if (workflow != null)
{
document.CheckOut();
document.SetValue("SomeFIeld", "some value");
document.Update(true);
document.CheckIn(versionComment: "admin_edit");
document.Publish();
}
and then, in event handler, take last version and check for comment like this:
if (e.PublishedDocument?.VersionHistory?.Count > 0)
{
var lastVersion = e.PublishedDocument.VersionHistory[0] as VersionHistoryInfo;
if (lastVersion.VersionComment.Equals("admin_edit"))
{
return;
}
}
NOTE: In case that you have a lot of concurrent content editors, there is a chance that your last version is not version from API (someone changed content and saved it right after your API call made change). There is a low chance for that, but still is possible. If this is something that you will use often, you must take it in consideration. This code is tested for Kentico 11.

Trying to delete a Miscellaneous Log Entry via eConnect - possible

I have a snippet of code that creates one or more Miscellaneous Log Entries via eConnect. If the code fails to create an entry, then all successfully created entries should be deleted.
E.g. (pseudo-code)
List<string> xmlDocs = new List<string>();
try
{
for (int index = 0; index < entries.Count; index++)
{
// Create taPAMiscLogHdrInsert
// Create taPAMiscLogLineInsert_ItemsTaPAMiscLogLineInsert[]
// Create PAMiscLogExpenseType and set the fields to above
// Generate the XML
xmlDocs.Add(econnect.CreateTransactionEntity(connectionString, xml)
}
}
catch
{
for (int index = 0; index < xmlDocs.Count; index++)
{
eConnect.DeleteTransactionEntity(connectionString. xmlDocs[index];
}
}
The DeleteTransactionEntity call fails with 'Duplicate Misc Log Entry' which makes sense since the XML from the CreateTransactionEntity call contains HdrInsert nodes.
This leads me to believe that you cannot programmatically delete Miscellaneous Log Entries, but I thought I'd ask.
Anyone know if this is possible?

MFC Redo Function

I m trying with the Redo option, I have written the following code for Redo but insted of Redo Undo is working for the same. Please guide me where i went wrong.
My code sample is.....
void EIWBDoc::OnEditRedo() //for REDO.
{
// TODO: Add your command handler code here
int Index = m_FigArray.GetUpperBound ();
if (Index > -1)
{
delete m_FigArray.GetAt(Index);
m_FigArray.RemoveAt (Index);
}
UpdateAllViews (0);
SetModifiedFlag ();
}
void EIWBDoc::OnUpdateEditRedo(CCmdUI* pCmdUI) //for redo.
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (m_FigArray.GetSize ());
}
i m storing all the deleted means the Undo contents into one array.Now i need to call the same into my Redo(). How should i do?
From this small snippet, it looks like you are removing the last 'fig' to have been added. This sounds more like an 'undo' behaviour.
I suspect that you want to add the last 'fig' to have been 'undone', having stored it in your 'undo' method.
Your command enabler will need to only enable 'redo' functionality when there is something to be 'redone', not when there are 'figs' in your document.

Resources