I am initialize object in node js
let obj = {};
let count = 0;
now adding in object
obj[count].Id = ID;
It will give me error that Id not defined
Solution is
let obj = [{}];
now it is working fine for me
I suppose you want to add Id property to "obj".
You can simply add it like :
obj["Id"] = ID;
Related
I'm using PDFTron's Java SDK, and I want to change the name of an element, then write the modified PDF to a new file, but I get the following output:
PDFNet is running in demo mode.
Permission: read
Exception:
Message: SetName() can't be invoked on Obj of this type.
How can I change an object's name? My code (in Scala) is as follows:
def main(args: Array[String]): Unit = {
PDFNet.initialize()
var doc = new PDFDoc("example.pdf")
var fdf = doc.fdfExtract
var iter = fdf.getFieldIterator
while (iter.hasNext) {
var field = iter.next
var obj = field.findAttribute("T")
if (obj != null && field.getName.startsWith("MyPrefix")) {
obj.setName("NewPrefix") // `field.setName` produces the same error
}
}
}
The API Field.GetName() is technically an amalgamation of this leaf Field and any parent ones, delimited by a ..
So while Field.getName() might return name.first the Field's T value might just be first. This is why there is Field.getPartialName() exists.
So the better/safer code to change the T value is.
var obj = field.findAttribute("T")
if (obj != null && obj.isString() && obj.getAsPDFText().startsWith("MyPrefix")) {
obj.setString("NewPrefix")
}
I am using node.js and n-api. The gist of it is that I cannot create a new object within a for loop without getting a type error that says:
TypeError: wrappedExamData.getPatientID is not a function
This only occurs when trying to create an object the second time. The first time works fine, though. If I create multiple new objects outside of the for loop, it works fine as well.
Here is the module that is throwing the error
//Require the node module
const nodeModule = require('../../../build/Release/QTWebUI.node');
//Require the Exam Class
const Exam = require('./Exam.js');
exports.retrieveAllExams = function(){
// Create a js wrapped c++ class to get a list of exam IDs
var msgGetExamList = new nodeModule.EMGetExamList_Wrapped();
// Create an array of the examIDs
var examList = msgGetExamList.getExamIDs();
console.log(examList);
var examArray = new Array();
for(let i = 0; i < examList.length; i++){
// Create a js wrapped c++ class to send get exam to scanner
var msgGetExam = new nodeModule.EMGetExam_Wrapped(examList[i]);
// Get the js wrapped examData from the c++ class
var wrappedExamData = msgGetExam.getWrappedExamData();
// Create a new exam object with the wrapped examData
var exam = new Exam(wrappedExamData);
// Print the newly created exam object
console.log("Exam: %s", JSON.stringify(exam));
// Push to array
examArray.push(exam);
}
return examArray;
};
Here is the Exam class that I am using where the error is traced back:
module.exports = internal.Exam = class{
constructor(wrappedExamData){
this.patientID = wrappedExamData.getPatientID();
this.firstName = wrappedExamData.getFirstName();
this.lastName = wrappedExamData.getLastName();
this.middleName = wrappedExamData.getMiddleName();
this.gender = wrappedExamData.getGender();
this.birthDate = wrappedExamData.getBirthDate();
this.scanTime = wrappedExamData.getScanTime();
this.description = wrappedExamData.getDescription();
this.breast = wrappedExamData.getBreast();
this.accession = wrappedExamData.getAccession();
this.operatorsName = wrappedExamData.getOperatorsName();
this.examState = wrappedExamData.getExamState();
this.progress = wrappedExamData.getProgress();
this.archiveMultiplicity = wrappedExamData.getArchiveMultiplicity();
this.density = wrappedExamData.getDensity();
this.targetType = wrappedExamData.getTargetType();
this.fromMWL = wrappedExamData.getFromMWL();
}
}
If I instantiate the objects like this:
// Create a js wrapped c++ class to send get exam to scanner
var msgGetExam = new nodeModule.EMGetExam_Wrapped(examList[0]);
// Get the js wrapped examData from the c++ class
var wrappedExamData = msgGetExam.getWrappedExamData();
// Create a new exam object with the wrapped examData
var exam = new Exam(wrappedExamData);
// Print the newly created exam object
console.log("Exam: %s", JSON.stringify(exam));
// Push to array
examArray.push(exam);
// Create a js wrapped c++ class to send get exam to scanner
var msgGetExam1 = new nodeModule.EMGetExam_Wrapped(examList[1]);
// Get the js wrapped examData from the c++ class
var wrappedExamData1 = msgGetExam1.getWrappedExamData();
// Create a new exam object with the wrapped examData
var exam1 = new Exam(wrappedExamData1);
// Print the newly created exam object
console.log("Exam: %s", JSON.stringify(exam1));
// Push to array
examArray.push(exam1);
It works fine. Is there something I'm missing here?
I'm writing a little nodeJS based email server. I have a Request object, and in it there's one static variable that stores all the users and is defined like so:
Request.publicMemory = new Object();
Request.publicMemory.users = new Object();
Request.prototype.getPublicMemory = function() {
return (Request.publicMemory);
};
I store User objects in it:
function User(params) {
this.mails = new Array();
this.sent = new Array();
var details = new Object();
details.username = params.username;
details.password = params.password
return;
}
As you can see there's also a static function that returns it.
Now, I can add uesrs and that change is actually made, but when I change anything in Request.publicMemory.usesrs[someuser] the change is always local to the function, and does not take effect in other places. Here's an example of how I do it:
function addMail(request) {
var users = request.getPublicMemory().users;
var to = request.parameters['to'];
users[to].mails.push(mail);
}
I've never used a static variable in nodeJS before, and I'm quite new to it so this might be silly, but I still can't solve it. Any ideas?
Thanks!
I know my question is really easy but i can't get its solution since last three hours.
I have created a gridview which has three columns PeriodID,PeriodName and Checkbox.
now when i go through for each loop for this grid,i want to get periodid value of each row in this gridview..
for this i have writen code like this.
foreach (GridViewRow row in gvdchk.Rows)
{
int i = row.RowIndex;
var cb = (HtmlInputCheckBox)row.FindControl("chkPaid");
var Periodid = gvdchk.Rows[i].FindControl("PeriodID");
//string su = Periodid.ToString();
// Guid PeriodID = Guid.Parse(su);
// Guid guid = new Guid(Periodid);
//var PeriodID = row.FindControl("PeriodID");
//Guid PeriodId = (Guid) PeriodID;
//Guid PeriodId = (Guid)(gvdchk.Rows[row.RowIndex].FindControl("datemonth2"));
// int order = m.bussinesCollection.BussinesPeriod.GetOrder(PeriodID);
if (cb != null && cb.Checked)
{
}
}
When I debug my code,I found that var Periodid gets the correct value of the period id but I want it as Guid.
Can anyone help in this..?
The following code that you have in your post
Guid guid = new Guid(Periodid);
will work fine to convert the string to GUID.
You can also check what is the datatype for the Periodid that you get in the line no. 5 of your code.
For some reason I need to save some big strings into user profiles. Because a property with type string has a limit to 400 caracters I decited to try with binary type (PropertyDataType.Binary) that allow a length of 7500. My ideea is to convert the string that I have into binary and save to property.
I create the property using the code :
context = ServerContext.GetContext(elevatedSite);
profileManager = new UserProfileManager(context);
profile = profileManager.GetUserProfile(userLoginName);
Property newProperty = profileManager.Properties.Create(false);
newProperty.Name = "aaa";
newProperty.DisplayName = "aaa";
newProperty.Type = PropertyDataType.Binary;
newProperty.Length = 7500;
newProperty.PrivacyPolicy = PrivacyPolicy.OptIn;
newProperty.DefaultPrivacy = Privacy.Organization;
profileManager.Properties.Add(newProperty);
myProperty = profile["aaa"];
profile.Commit();
The problem is that when I try to provide the value of byte[] type to the property I receive the error "Unable to cast object of type 'System.Byte' to type 'System.String'.". If I try to provide a string value I receive "Invalid Binary Value: Input must match binary byte[] data type."
Then my question is how to use this binary type ?
The code that I have :
SPUser user = elevatedWeb.CurrentUser;
ServerContext context = ServerContext.GetContext(HttpContext.Current);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile profile = GetUserProfile(elevatedSite, currentUserLoginName);
UserProfileValueCollection myProperty= profile[PropertyName];
myProperty.Value = StringToBinary(GenerateBigString());
and the functions for test :
private static string GenerateBigString()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 750; i++) sb.Append("0123456789");
return sb.ToString();
}
private static byte[] StringToBinary(string theSource)
{
byte[] thebytes = new byte[7500];
thebytes = System.Text.Encoding.ASCII.GetBytes(theSource);
return thebytes;
}
Have you tried with smaller strings? Going max on the first test might hide other behaviors. When you inspect the generated string in the debugger, it fits the requirements? (7500 byte[])
For those, who are looking for answer. You must use Add method instead:
var context = ServerContext.GetContext(elevatedSite);
var profileManager = new UserProfileManager(context);
var profile = profileManager.GetUserProfile(userLoginName);
profile["MyPropertyName"].Add(StringToBinary("your cool string"));
profile.Commit();