I fetch data from a task and want to store the data in repo.
This is my code:
function saveToRepo(item) {
try {
const result = contentLib.create({
name: 'market_news_' + item.guid.contents,
displayName: item.title,
contentType: `${app.name}:marketNews`,
parentPath: '/',
data: item
})
log.info('Content created with id ' + result._id);
} catch (e) {
if (e.code == 'contentAlreadyExists') {
log.error('There is already a content with the name %s', item.title);
} else {
log.error('Unexpected error: ' + e.message);
log.info('item: ' + JSON.stringify(item, null, 2));
}
}
}
I call this from a different context contextLib.run(CTX, saveToRepo(item));
, where item is a JSON-Object which fits in the content-type definition.
EDIT: When I log the current context inside saveToRepo, shouldn’t I get the context set by contextLib.run (= CTX)?
This ends up in the following errors:
from saveToRepo(item)
ERROR org.lienas.webpack - (/tasks/fetchnews/fetchnews.js) Unexpected error: null
and then:
ERROR c.e.x.i.task.script.NamedTaskScript - Error executing named task [org.lienas.webpack
:fetchnews] 'News abrufen' with id 4dfc271c-c0b7-4de3-bf73-3fc92a5d1b6e: Cannot cast jdk.nashorn.internal.runtime.Undefined to java.util.concurrent.Callable
java.lang.ClassCastException: Cannot cast jdk.nashorn.internal.runtime.Undefined to java.util.concurrent.Callable
at java.base/java.lang.Class.cast(Class.java:3605)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1284$1231AA$context.L:1#run(org.lienas.webpack:/lib/xp/context.js:31)
When I run without defining the context, I only get the first error!