How do I do a recycle for GetNextDocument or GetNextCategory in a NotesViewNavigator? Neither takes an argument so you can't use the conventional method of using a temp variable to pre get the next document like you might in a view.
I suppose the solution would be to just use getNext with an argmenumnt but can GetNextDocument / GetNextCategory still be used?
The error I am getting is on line 20. Without the recycle the code runs fine. From what I understand recycle destroys the object so I can understand the reason for the error. My questition is if there is another way around this?
[TypeError] Exception occurred calling method NotesViewNavigator.getNextDocument() null
occurs on line 20
1: var viewName = "vwParticipantsProjectIDEquipmentIDUsername";
2:
3:
4: var v:NotesView = database.getView(viewName);
5: var nav:NotesViewNavigator = v.createViewNavFromCategory(sessionScope.get("ExportProjectID"));
6:
7:
8: var viewEnt:NotesViewEntry = nav.getFirstDocument();
9:
10: while (viewEnt != null)
11: {
12:
13: if (viewEnt.isDocument())
14: {
15:
16: var doc:NotesDocument = viewEnt.getDocument();
17: }
18:
19: viewEnt.recycle();
20: viewEnt = nav.getNextDocument();
21: }
This is the pattern that I tend to use:
var documentEntry = nav.getFirstDocument();
while( documentEntry != null ){
var nextDocumentEntry = nav.getNextDocument();
// do stuff
documentEntry.recycle();
documentEntry = nextDocumentEntry;
}
Why don't you try to apply the old pattern like this:
var viewName = "vwParticipantsProjectIDEquipmentIDUsername",
v:NotesView = database.getView(viewName),
nav:NotesViewNavigator = v.createViewNavFromCategory(sessionScope.get("ExportProjectID")),
viewEnt:NotesViewEntry = nav.getFirstDocument(),
tmp:NotesViewEntry;
while (viewEnt !== null)
{
if (viewEnt.isDocument())
{
var doc:NotesDocument = viewEnt.getDocument();
}
tmp = viewEnt;
viewEnt = nav.getNextDocument();
tmp.recycle();
}
I did not test it, but I guess that works...
Related
switch (numYears) {
case 10:
intsRate = 0.06;
break;
case 15:
intsRate = 0.05;
break;
case 30:
intsRate = 0.04;
break;
default:
intsRate = 0.08;
break;
}
return intsRate;
}
when the input of numYears is 10, 15, or 30 its returns the according double, but its only returning the defult. its part of a larger code but everything in that code is right this is the only part returning the wrong thing.
I am getting an Error in specialCodes[letter] saying Element implicitly has an 'any' type because expression of type 'string' can't be used to index type and No index signature with a parameter of type 'string' was found on type
import { Message, MessageEmbed } from "discord.js";
import BaseCommand from "../../utils/structures/BaseCommand";
import DiscordClient from "../../client/client";
export default class EmojifyCommand extends BaseCommand {
constructor() {
super("emojify", "fun", []);
/**
* #param {Client} client
* #param {Message} message
* #param {String[]} args
*/
}
async run(client: DiscordClient, message: Message, args: Array<string>) {
const embedSpecify = new MessageEmbed();
embedSpecify
.setColor("RED")
.setDescription("Please specify a text to translate!");
if (!args.length) return message.reply({ embeds: [embedSpecify] });
const specialCodes = {
0: ":zero:",
1: ":one:",
2: ":two:",
3: ":three:",
4: ":four:",
5: ":five:",
6: ":six:",
7: ":seven:",
8: ":eight:",
9: ":nine:",
"#": ":hash:",
"*": ":asterisk:",
"?": ":grey_question:",
"!": ":grey_exclamation:",
" ": " ",
};
const text = args
.join(" ")
.toLowerCase()
.split("")
.map((letter) => {
if (/[a-z]/g.test(letter)) {
return `:regional_indicator_${letter}:`;
} else if (specialCodes[letter]) {
return `${specialCodes[letter]}`;
}
return letter;
})
.join("");
message.reply(text);
}
}
You have mixed types of keys in specialCodes and you need to help TS to understand how to get values from there. Something like this:
const specialCodes: Record<number | string, string> = {
0: ":zero:",
1: ":one:",
2: ":two:",
3: ":three:",
4: ":four:",
5: ":five:",
6: ":six:",
7: ":seven:",
8: ":eight:",
9: ":nine:",
"#": ":hash:",
"*": ":asterisk:",
"?": ":grey_question:",
"!": ":grey_exclamation:",
" ": " ",
};
my idea is to create a microservice that:
A- Reads everything from a collection
B- Does a loop with all that data
C- Inside the loop, each time calls another collection to get reference data from each item
ex:
#Cron('*/10 * * * * *')
async runEvery10Seconds() {
console.log("log 1");
let allDataFromCollection= await this.findAllData();
for (let i = 0; i != allDataFromCollection.length; i++) {
let item1Id = this.referencedb(allDataFromCollection[i].item1value);
let item2Id = this.referencedb(allDataFromCollection[i].item2value);
let item3Id = this.referencedb(allDataFromCollection[i].item3value);
// then I create a JSON with this new data
let data = {
item1 = item1Id ,
item2 = item2Id,
item3 = item3Id
}
this.sendHttpPost(data);
}//close for
}
Things never reach the HttpPost and the only output is the first console log ("log 1") in loop, until the code terminates with
5: 00007FF7428063BD v8::SharedArrayBuffer::Externalize+781
6: 00007FF7426B084C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516
7: 00007FF7426BBB8A v8::internal::Heap::ProtectUnprotectedMemoryChunks+1258
8: 00007FF7426B8D39 v8::internal::Heap::PageFlagsAreConsistent+2457
9: 00007FF7426AD961 v8::internal::Heap::CollectGarbage+2033
10: 00007FF7426ABB65 v8::internal::Heap::AllocateExternalBackingStore+1317
11: 00007FF7426C5E06 v8::internal::Factory::AllocateRaw+166```
I was just trying Apache Thrift in nodejs before using it in my upcoming project wherein I ran into this error.
Here is my demo.thrift file
namespace js demo
typedef i32 int
enum Operation {
ADD = 1,
SUBTRACT = 2,
MULTIPLY = 3,
DIVIDE = 4
}
struct Work {
1: int num1 = 0,
2: int num2,
3: Operation op,
4: optional string comment
}
exception InvalidOperation {
1: int message,
2: string trace
}
service Calculator {
void ping()
double calculate(1: int logid, 2: Work w) throws (1: InvalidOperation oops),
oneway void zip()
}
Here is a part of the server.js
I use switch case to determine operation in server.js
// inside thrift.createServer
calculate: (logid, work, result) => {
let answer = null, oops = null;
switch(work.op) {
// Code related to Operation.ADD, Operation.SUBTRACT ...
default: {
console.log("ERROR!");
oops = InvalidOperation();
oops.message = work.op;
oops.trace = "Unknown Operation";
}
}
result(oops, answer);
}
When the client.js calls server with calculate(12345, { num1:1, num2:2, op: 10 })
Instead of returning an error it throws
TypeError: Cannot set property 'name' of undefined in demo_types.js:122
The part related to InvalidOperation in demo_types.js is
// Work related code
var InvalidOperation = module.exports.InvalidOperation = function(args) {
Thrift.TException.call(this, "InvalidOperation");
this.name = "InvalidOperation"; // points to here
this.message = null;
this.trace = null;
if (args) {
if (args.message !== undefined && args.message !== null) {
this.message = args.message;
}
if (args.trace !== undefined && args.trace !== null) {
this.trace = args.trace;
}
}
};
Thrift.inherits(InvalidOperation, Thrift.TException);
InvalidOperation.prototype.name = 'InvalidOperation';
// InvalidOperation.read & .write
Any idea why the error is being thrown?
Actually I realised why this error is being thrown. It is a plain old Javascript mistake.
oops = new InvalidOperation();
That's it.
I use Jscript to enable Keystrokes in Qualtrics to answer a question.
It works as with 2 options as provided in the example by Qualtrics: https://www.qualtrics.com/university/researchsuite/developer-tools/custom-programming/example-code-snippets/#ExampleJavaScript
I added a third Keystroke option (press q) which is not working: somehow the keystroke for q is registered but neither does it enter the data nor proceed to the next question as is the case when pressing j or k. See code below. Any advise appreciated - thanks!
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place Your Javascript Below This Line*/
this.hideNextButton();
this.hidePreviousButton();
var that = this;
Event.observe(document, 'keydown', function keydownCallback(e) {
var choiceID = null;
switch (e.keyCode) {
case 74: // 'j' was pressed
choiceID = 1;
break;
case 75: // 'k' was pressed
choiceID = 2;
break;
case 81: // 'q' was pressed
choiceID = 5;
break;
}
if (choiceID) {
Event.stopObserving(document, 'keydown', keydownCallback);
that.setChoiceValue(choiceID, true);
that.clickNextButton();
}
});
});
});
I'm not sure exactly what is wrong. A few different things it could be:
1) Your code above has an extra }); at the end. However, Qualtrics wouldn't let you save that, so I'm thinking it is just a typo in your post above.
2) If your choiceID is wrong and you have force response turned on, then it won't advance and you'll get an error message.
3) If you are in JFE preview mode, then you have to first get focus on the form before any keypress will work.
BTW, this won't work on mobile devices.
Here is some cleaned up code that also fixes issue (3):
Qualtrics.SurveyEngine.addOnload(function()
{
$('Buttons').hide();
if(window.location.pathname.match(/^\/jfe[0-9]?\/preview/)) {
$(this.questionId).select('input').first().focus();
}
var that = this;
Event.observe(document, 'keydown', function keydownCallback(e) {
var choiceID = null;
switch (e.keyCode) {
case 74: // 'j' was pressed
choiceID = 1;
break;
case 75: // 'k' was pressed
choiceID = 2;
break;
case 81: // 'q' was pressed
choiceID = 5;
break;
}
if (choiceID) {
Event.stopObserving(document, 'keydown', keydownCallback);
that.setChoiceValue(choiceID, true);
$('NextButton').click();
}
});
});