page.evaluate doesn't work - node.js

I want page.evaluate to run when my onLoadFinished is complete. But the following error is coming
MESSAGE: ReferenceError: Can't find variable: page
my code is:
page.property('onLoadFinished', function(status) {
if(status==="success")
{
try{
console.log('==== onLoadFinished()'+status);
page.evaluate(function () {
console.log("++++++++++++++++++"+document);
var Import = document.getElementById("Import");
if (Import){
console.log("+"+Import);
document.getElementById("start").value = "somedate";
document.getElementById("Import").click();
}else{console.log("Import not found");}
})
}catch(ex){
var fullMessage = "\nJAVASCRIPT EXCEPTION";
fullMessage += "\nMESSAGE: " + ex.toString();
for (var p in ex) {
fullMessage += "\n" + p.toUpperCase() + ": " + ex[p];
}
console.log(fullMessage);
}
}
})

page isn't a global variable as far as I know. You could use windows.onload instead.
It fires when the entire page is loaded. So this is what you need!

Related

Workflow C# string function error in Docusign

I have an code issue in docusign.
In my calculation step I have created and input and output code.
When I run the template and checking the "incoming data" xml in the workflow I have an error message displayed:
<In_80_stackTrace>Exception: at ADEXS.DynamicCode.DynamicClassD_3447d8ccd49f4631b91c31df53e249e7.DynamicMethodD_dcb572b7876d400683579290c5918f06(DynamicContext _context)</In_80_stackTrace>
I don't know how to fix this that it will show only the
logError("In_80_error", "Data node //CategoryName is missing");
when no data is in the node.
Below are the details - my input code:
//In_80 - ESP_CategoryName_Description
string In_80 = "";
{
try
{
if (incomingDataRoot.SelectSingleNode("//CategoryName[node()]").InnerText == null)
{
logError("In_80_error", "Data node //CategoryName is missing");
}
else if (incomingDataRoot.SelectSingleNode("//CategoryName[node()]").InnerText != null)
{
In_80 = incomingDataRoot.SelectSingleNode("//CategoryName[node()]").InnerText;
}
}
catch (Exception e)
{
//logError("In_80_error", "Exception: Message:" + e.Message +" Inner Exception: "+ e.InnerException +" StackTrace: "+ e.StackTrace +" Source: "+ e.Source +" Data: "+ e.Data);
logError("In_80_stackTrace", "Exception: " + e.StackTrace);
}
}
Here is the output code:
//OUT_92 - ESP_CategoryName_Description
var OUT_92 = In_80;
if (In_80 == "")
{
logError("OUT_92_error", "Error reading In_80");
} else {
XmlElement elem = incomingDataRoot.OwnerDocument.CreateElement("OUT_92");
string p_category = "";
int i = 1;
foreach (char item in In_80)
{
if (Char.IsLetter(item))
{
if (i == 1)
{
p_category += item.ToString().ToUpper();
}
else
{
p_category += item.ToString().ToLower();
}
i++;
}
else
{
if (item == ' ')
{
i = 1;
}
p_category += item.ToString();
}
}
OUT_92 = p_category;
elem.InnerText = OUT_92.ToString();
elem.SetAttribute("Name", "ESP_CategoryName_Description");
incomingDataRoot.SelectSingleNode("/Root/Params/TemplateFieldData/Calculation_Results").AppendChild(elem);
}
In incoming data OUT part I'm getting
<OUT_92_error>Error reading In_80</OUT_92_error>
where I assume that its because something is wrong with the input code part?
Thank you for your help!

Run an event only once in NodeJS but use the data multiple times

So I have written this code :
manager.getInventoryContents(730, 2, true, (err,inventory,currencies) => {
if (err){
console.log(err)
} else {
console.log("Create order for : " + orderitemname.length + " items.")
var otn = orderitemname.length -1;
while (otn !== -1) {
var li= inventory.length - 1;
while (li !== -1){
if (inventory[li].market_name === orderitemname[otn]){
console.log("Add item to trade " + orderitemname[otn]);
li = li -1;
otn = otn -1;
} else {
console.log("ERR !!! ITEM NOT IN INVENTORY !!! " + orderitemname[otn]);
//Change Order Status To Failed !!
n = n-1;
otn = -1;
li = -1;
}
}
}
}
})
So what is happening is that the process is calling this event multiple times (since it is in a while loop), and the node module is ignoreing it saying :
Error: The request is a duplicate and the action has already occurred in the past, ignored this time
So is there a way I can just call the event once, save it to a variable or something and then use the data multiple time ?
You can wrap everything in a new context and initiate whatever variable you need there. Then, the variable will be accessible from within your callback function.
Something like this:
(() => {
let ctx_data = 0;
manager.getInventoryContents(730, 2, true, (err,inventory,currencies) => {
console.log(++ctx_data);
});
})();

jslink only renders when I engage cisar inspector

Cisar verifies the jslink is getting called correctly but rendering only happens when I open the file with the cisar inspector. Weird.
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Header = "<div class='row'><div class='col-md- 8'>Title</div><div class='col-md-1'>Screen 16x9</div><div class='col-md-1'>Print</div><div class='col-md-2'>Updated</div>";
overrideCtx.Templates.Footer = "</div>";
overrideCtx.Templates.Item = CustomItem;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
function CustomItem(ctx) {
// Build a listitem entry for every announcement in the list.
var ret = "<div class='col-md-8'>" + ctx.CurrentItem.Title + "</div><div class='col-md-1'><a href='https://domain/subsite/library/" + ctx.CurrentItem.FileLeafRef + "'><i class='fa fa-tv fa-2x'></i></a></div><div class='col-md-1'><a href='" + ctx.CurrentItem.Print_x0020_4x3 + "'><i class='fa fa-print fa-2x'></i></a> </div>" "<div class='col-md-2'>" + ctx.CurrentItem.Updated + " </div>"
;
return ret;
}

Include Data In A Response/Reply From A Primefaces Push

Is there a way to include data from the front-end to send to the back end, perhaps in the reply.completed argument, such that if a condition was not met, the front end can inform the backend of the status and the backend and do something with that data? And if so, how?
From the back-end:
Reply reply = new Reply() {
#Override
public void completed(String arg0) {
System.out.println("Reply received: " + arg0);
}
};
summary = this.getText("report.ready.view").replace("{0}", reportName);
reportLink = this.getExternalContextRoot() + reportLink + (!reportLink.contains("?") ? "?reportId=" : "&reportId=") + savedReportStatus.getSavedReportStatusId();
detail = "<a href='" + reportLink + "'>" + this.getText("click.to.view") + "</a>";
facesMessage = new FacesMessage(severity, summary, detail);
eventBus.publish(channel, facesMessage, reply);
From the front-end:
<p:socket onMessage="handleMessage" channel="/reports/#{userSessionBean.userID}" autoConnect="true"/>
<script type="text/javascript">
function handleMessage(message) {
if (DO SOME CHECK) {
if (message.severity == 'INFO 0') {
message.severity = 'info';
} else if (message.severity == 'WARN 1') {
message.severity = 'warn';
} else if (message.severity == 'ERROR 2') {
message.severity = 'error';
} else if (message.severity == 'FATAL 3') {
message.severity = 'fatal';
}
PF('reportsGrowl').show([message]);
updateViewedReports();
} else {
SEND THE BACK-END INFORMATION INDICATING THE CHECK FAILED AND THE MESSAGE WAS NOT SHOWN
}
}
$(document).ready(function () {
updateViewedReports();
});
</script>

Error when using fiber dependent wait.for npm module in Node.js

Im using the wait.for library to get rid of some asynchronous calls. Im doing this because I don't really care much about having my server run efficiently or anything, I'm using node.js for some data processing using the Natural NLP npm module.
Anyways, Im recursively building a tree and requesting an wikipedia article for each node. That wikipedia request is asynchronous and I am trying to make it synchronous via a call to wait.for(...). The request works fine if the recursive call ends after just one activation, but throws an error if the recursion carries on any further.
Visually, I mean
[ROOT]
/ | \
[] [] [] <--- This level is fine ... No Errors
|
[] <--- Error Here, on level 2
The error is:
/Users/me/Documents/Node Projects/Personal Website/node_modules/wait.for/waitfor.js:37
fiber.run(); //resume fiber after "yield"
^
TypeError: Cannot call method 'toString' of undefined
at TfIdf.tfidf (/Users/me/Documents/Node Projects/Personal Website/node_modules/natural/lib/natural/tfidf/tfidf.js:132:42)
at isIrrelevant (/Users/me/Documents/Node Projects/Personal Website/finalproject/wikitree.js:126:47)
Here is the code for the recursive call:
var WikiTree = function(node) {
this.name = node.name;
this.context = node.context;
this.text = node.article;
if (node.children) {
this.children = node.children;
}
function createArticleSummary(article) {
// TODO: Must Implement
return article;
}
function isIrrelevant(article, title, linkText) {
// Tweak Here
var articleTfIdf = new TfIdf();
articleTfIdf.addDocument(article);
var titleRelevanceToArticle = articleTfIdf.tfidf(title,0); // ERROR HERE: This is wikitree.js:126
var textRelevanceToArticle = articleTfIdf.tfidf(linkText,0);
var titleRelevanceToZen = zenTfidf.tfidf(title,0);
var textRelevanceToZen = zenTfidf.tfidf(linkText,0);
return ( titleRelevanceToZen / titleRelevanceToArticle >= 1 ) || ( textRelevanceToZen / textRelevanceToArticle >= 1 );
}
WikiTree.prototype.searchChild = function(child) {
console.log("Searching for Link Title \"" + child.title + "\" And Link Text \"" + child.linkText + "\"");
var childQuery = {
query : child.title,
format : "html",
summaryOnly : false
};
var childArticle = wait.for(wikipedia.searchArticle, childQuery);
console.log("Got Wikipedia Response for " + child.title);
var childWikiLinks = extractLinkedWikis(childArticle);
console.log("Found " + childWikiLinks.length + " Links for " + child.title);
for (var i = childWikiLinks.length - 1; i >= 0; i--) {
if ( LinkTrie.contains(childWikiLinks[i].title) || LinkTrie.contains(childWikiLinks[i].linkText) ) {
childWikiLinks.splice(i,1);
} else if ( isIrrelevant( childWikiLinks[i] ) ) {
childWikiLinks.splice(i,1);
} else {
LinkTrie.addStrings([ childWikiLinks[i].title, childWikiLinks[i].text ]);
}
};
console.log("After pruning, " + childWikiLinks.length + " Links left for " + child.title);
var newChildWT = new WikiTree({
name : child.title,
context : child.linkText,
article : childArticle,
children : createArticleSummary(childWikiLinks)
});
return newChildWT;
};
WikiTree.prototype.descend = function() {
// Descend to the next level ... Meaning find the children of the current children (If there are any)
if (!this.children) {
console.log("Leaf at " + this.name);
return;
}
for (var i = this.children.length - 1; i >= 0; i--) {
if ( this.children[i].title.match(/Category:/) ) {
console.log("Found 'Category:' at " + i + " in " + this.children[i].title);
this.children.splice(i,1);
} else
this.children[i] = this.searchChild(this.children[i]);
};
console.log("Done With Descend For " + this.name);
};
this.descend();
};
var result = ...; // A String
var zenLinks = ...; // An Array of objects
// Actually make the first recursive call here
var zenTree = new WikiTree({
name : 'Zen & The Art of Motorcycle Maintenance',
article : result,
children : zenLinks
});
Anyways, any help will be much appreciated. There wasn't much help from googling the issue so anyone that has had experience with either wait.for or node fibers could greatly help me out.
I think you might do this:
var childArticle = wait.forMethod(wikipedia, 'searchArticle', childQuery);

Resources