Node BehaviorSubject Problem only get empty object - node.js

I am using Angular version 7 and trying to use a BehaviorSubject
but when I get the value, all times I receive an empty object
value empty
line: 315 | let value: any = await this._service.machine$.pipe(take(1)).toPromise()
Emmit
this._service.emitterMachineSelected('new')
code of service

_machine's default value
_machine is a BehaviorSubject that (to start with) contains an empty object. ({} is an empty object). That's how you read the following line:
_machine = new BehaviorSubject({});
So when you grab that value, an empty object (The default value of the BehaviorSubject) is what you get.
Using .next to emit a value
Some time later, it contains the string "new"
this_machine.next("new");
You're not grabbing this value anywhere, so you shouldn't expect to see it anywhere.

Related

Unable to parse XML object

(I don't use Node-Red for a long time but I have some knowledge of Javascript syntax using NodeJS and client side libraries like jQuery.)
I can read my file and parse it correctly. Data object is valid (see green arrow) and syntax to access structured object is good.
let arr = msg.payload
.VariablesExchangeFile
.DDTSource[0]
.structure[0]
.variables;
return arr;
But My arr variable is empty (see red arrow) !!! And I don't understand why.
I copied the path to the child object from debug Window, and it's the same path (see yellow shapes) : payload.VariablesExchangeFile.DDTSource[0].structure[0].variables
The variable is not empty, the problem is that you are not returning a msg object from the function node.
You are returning the array object which does not have a payload field and you have the debug node set to only print out the msg.payload field.
Change the function node as follows:
let msg.payload = msg.payload
.VariablesExchangeFile
.DDTSource[0]
.structure[0]
.variables;
return msg;

Cloud Function ArrayRemove not deleting array value, but function runs without error

My cloud function is not deleting value from the array it is suppose to. It gets all the values correctly as I see in my debug console, but the value in the array is still there.
My code statement is as follows:
for (const id of membersUnderStructure){
const ele = context.params.structure;
console.log(`Deleting ${ele} From ${id}`);
await db.collection(`TeamMember`)
.doc(id)
.update({teamStructIds: admin.firestore.FieldValue.arrayRemove(ele)})
I know the problem is with the admin.firestore.... line as if I put a constant value there, it does update fine. My console shows the correct value of 'ele' and 'id' as well, so the values are correct. The function executes 'ok' without any error but does NOT delete the value of 'ele' from the 'teamStructIds' array.
I am not sure what am I doing wrong here?
Solution:
The Array is of 'Number' and it is trying to delete a String of 'ele'.
I just changed to parseInt(context.parama.structure) and it works now.

TypeError: Cannot read property 'substring' of undefined

Written in node.js file
The function is returning the error:
Returns the ACE occupation exhibit identifier
Example of originalID: 46R-002-30BroadJour12_01-12_11
Expected output: 46R-002
/*This function is returning the error:
Cannot read property 'substring' of undefined*/
function splitID(originalID){
var aceid = originalID.substring(0,7);
return aceid;
}
//1. Get the ace exhibit occupation id for each of them and put it in a parallel array.
for (var row in values) {
//split the 5th column using our function
var output = splitID(row[4]);
var result = getOccupation(output);
//now we add the split output to our occupation array.
occupationsToInsert.append(result);
}
If you may refer to the documentation here at MDN, it advises against using for...in for looping over the arrays because it does not give consistent values on return. It rather iterates on the enumerable properties of the concerned object passed to it.
In other words, for (var row in values) would not iterate over each individual rows as expected, but rather the enumerable properties of the values list.
So, for your const array, you can find the enumerable properties by simply doing
Object.getOwnPropertyNames(values)
which would return you the following list :
["0", "length"]
You're essentially trying to access the fourth element of this array which doesn't exist, and thereby it is undefined, causing the error you observe.
The error is telling you the exact problem: originalID is undefined. In your for loop, row[4] is resulting in an undefined value. Verify your values array contains what you are expecting.

In nodejs, when the method is called multiple times at the same time, is the variable is shared

I want to generate the short id of number type, but when I call shortid method and output id and emaill, the contents of the output in the console are the same as the incoming variable. the gist in github
I get an answer that change 'var self = this ' to 'var self = {}', because 'this' in method equal 'global'.

Can't modify/remove a field from an ActivityNode using sbt

I created an ActivityNode (an Entry) and I can add custom fields with the
setFields(List<Field> newListField)
fonction.
BUT
I am unable to modify these fields. (In this case I try to modify the value of the field named LIBENTITE)
FieldList list = myEntry.getTextFields();
List<Field> updatedList = new ArrayList<Field>();
//I add each old field in the new list, but I modify the field LIBENTITE
for(Field myField : list){
if(myField.getName().equals("LIBENTITE")){
((TextField)myField).setTextSummary("New value");
}
updatedList.add(myField);
}
myEntry.setFields(updatedList);
activityService.updateActivityNode(myEntry);
This code should replace the old list of fields with the new one, but I can't see any change in the custom field LIBENTITE of myEntry in IBM connections.
So I tried to create a new list of fields, not modifying my field but adding a new one :
for(Field myField:list){
if(!myField.getName().equals("LIBENTITE")){
updatedList.add(myField);
}
}
Field newTextField = new TextField("New Value");
newTextField .setFieldName("LIBENTITE");
updatedList.add(newTextField );
And this code is just adding the new field in myEntry. What I see is that the other custom fields did not change and I have now two custom fields named LIBENTITE, one with the old value and the second with the new value, in myEntry.
So I though that maybe if I clear the old list of Fields, and then I add the new one, it would work.
I tried the two fonctions
myEntry.clearFieldsMap();
and
myEntry.remove("LIBENTITE");
but none of them seems to work, I still can't remove a custom field from myEntry using SBT.
Any suggestions ?
I have two suggestions, as I had (or have) similar problems:
If you want to update an existing text field in an activity node, you have to call node.setField(fld) to update the field in the node object.
Code snippet from my working application, where I'm updating a text field containing a (computed) start time:
ActivityNode node = activityService.getActivityNode(id);
node.setTitle(formatTitle()); // add/update start and end time in title
boolean startFound = false;
// ...
FieldList textfields =node.getTextFields();
Iterator<Field> iterFields = textfields.iterator();
while (iterFields.hasNext()) {
TextField fld = (TextField) iterFields.next();
if (fld.getName().equals(Constants.FIELDNAME_STARTTIME)) {
fld.setTextSummary(this.getStartTimeString()); // NOTE: .setFieldValue does *not* work
node.setField(fld); // write updated field back. This seems to be the only way updating fields works
startFound=true;
}
}
If there is no field with that name, I create a new one (that's the reason I'm using the startFound boolean variable).
I think that the node.setField(fld) should do the trick. If not, there might be a way to sidestep the problem:
You have access to the underlying DOM object which was parsed in. You can use this to tweak the DOM object, which finally will be written back to Connections.
I had to use this as there seems to be another nasty bug in the SBT SDK: If you read in a text field which has no value, and write it back, an error will be thrown. Looks like the DOM object misses some required nodes, so you have to create them yourself to avoid the error.
Some code to demonstrate this:
// ....
} else if (null == fld.getTextSummary()) { // a text field without any contents. Which is BAD!
// there is a bug in the SBT API: if we read a field which has no value
// and try to write the node back (even without touching the field) a NullPointerException
// will be thrown. It seems that there is no value node set for the field. We
// can't set a value with fld.setTextSummary(), the error will still be thrown.
// therefore we have to remove the field, and - optionally - we set a defined "empty" value
// to avoid the problem.
// node.remove(fld.getName()); // remove the field -- this does *not* work! At least not for empty fields
// so we have to do it the hard way: we delete the node of the field in the cached dom structure
String fieldName = fld.getName();
DeferredElementNSImpl fldData = (DeferredElementNSImpl) fld.getDataHandler().getData();
fldData.getParentNode().removeChild(fldData); // remove the field from the cached dom structure, therefore delete it
// and create it again, but with a substitute value
Field newEmptyField = new TextField (Constants.FIELD_TEXTFIELD_EMPTY_VALUE); // create a field with a placeholder value
newEmptyField.setFieldName(fieldName);
node.setField(newEmptyField);
}
Hope that helps.
Just so that post does not stay unanswered I write the answer that was in a comment of the initial question :
"currently, there is no solution to this issue, the TextFields are read-only map. we have the issue recorded on github.com/OpenNTF/SocialSDK/issues/1657"

Resources