I want to load a saved search , and set "inactive" field to true.
Problem is I tried to load it , but it failed
I tried this :
var searchRec = record.load({ type: search.Type.SAVED_SEARCH, id: result.id, isDynamic: false });
Also read the help on the N/search module but no answer.
Related
I have a form on a page, I want a user to enter something in the form click submit, then make a request to MongoDB using the input of that form and render parts of that request onto a page, using nodejs, mongoose, and ejs
The schema of the collection has a field that always contains an object and I would like to search for a document in the collection that has a key that matches the input of the form.
The schema of the collection is
const ArrivalTimesSchema = new mongoose.Schema({
postcodeArrivalTimes: {
type: Object,
required: true,
},
workerId: {
type: String,
required: false
},
company: {
type: String,
required: true
},
})
And an example of postcodeArrivalTimes is
postcodeArrivalTimes = {AL95AT:"07:06", DL56EP:"13:06",AL14PL:"19:15"}
So in this case if someone input AL95AT into the input form I would want this document returned, how would I do that?
Not all documents would contain the key AL95AT but there could be multiple and I would like the last.
For this I think I can use .sort({ $natural: -1 }).limit(1) within a find() but I am not sure how to search for the keys within the object within the field.
Thank you for any help!!
let input = "input" //inputKeyValue
let query = {};
query[input] = { $exists: true };
db.collection.find(query).sort({ $natural: -1 }).limit(1)
I created a new custom field in the 'US' address form called 'email', so I can have an email address associated with both the bill to and ship to on a sales order in Netsuite. I am trying to update this field using Suitescript 2.0, but cannot seem to save the changes. Can anyone give any insight?
var salesorder = record.load({
type: record.Type.SALES_ORDER,
isDynamic: true,
id: 6835
});
var shippingAddressSubrecord = salesorder.getSubrecord({fieldId : 'shippingaddress'});
var email = shippingAddressSubrecord.getValue({fieldId : 'custrecord_email_address' }); //returns correctly
shippingAddressSubrecord.setValue({fieldId : 'custrecord_email_address', value: 'test2#gmail.com', ignoreFieldChange: true });
var salesorderid = salesorder.save({enableSourcing: true, ignoreMandatoryFields: true});
This gives the error: "type":"error.SuiteScriptError","name":"OPERATION_IS_NOT_ALLOWED","message":"The subrecord line has already been committed or cancelled. The previous subrecord reference is no longer valid. You must get another reference to the subrecord in order to perform this operation.",
Depends, which script type is this? User Even scripts for example, loading/saving the record would result in an error.
I'm trying to load a custom record like below:
var mergeRecord = record.load({
type: record.Type.'custrecord_merge_vendor',
id: '12',
isDynamic: true
});
This seems wrong.. but the equivalent for standard records is like below:
var objRecord = record.load({
type: record.Type.SALES_ORDER,
id: 157,
isDynamic: true,
});
How to do this ?
Like this:
var mergeRecord = record.load({
type: 'custrecord_merge_vendor',
id: '12',
isDynamic: true
});
You have the right idea, except that you are not passing the correct record type for your Custom Record into the type property. The correct value will just be the string that is your Custom Record's internal ID; it will start with customrecord_. You will not use the record.Type enumeration as that is only for native record types.
Because something like record.Type.'custrecord_merge_vendor' is not even valid syntax, I highly suggest you familiarize yourself with the fundamentals of the JavaScript language. You can find tons of introductory information and examples over at MDN
I have a mongoose model: (With a field that has a default)
var MySchema= new mongoose.Schema({
name: {
type: String,
required: true
},
isClever: {
type: Boolean,
default: false
}
});
I can save a model of this type by just saving a name and in mongoDB, only name can be seen in the document (and not isClever field). That's fine because defaults happen at the mongoose level. (?)
The problem I am having then is, when trying to retrieve only people called john and isClever = false:
MySchema.find({
'name' : 'john',
'isClever': false
}).exec( function(err, person) {
// person is always null
});
It always returns null. Is this something related to how defaults work with mongoose? We can't match on a defaulted value?
According to Mongoose docs, default values are applied when the document skeleton is constructed.
When you execute a find query, it is passed to Mongo when no document is constructed yet. Mongo is not aware about defaults, so since there are no documents where isClever is explicitly true, that results in empty output.
To get your example working, it should be:
MySchema.find({
'name' : 'john',
'isClever': {
$ne: true
}
})
Schema:
var SomeSchema = new Schema({
name: { type: String, required: true, unique: true },
description: { type: String, required: false }
},{
versionKey: false
}
);
// In this case the client did not pass me a description, which is ok cause this property is not required.
// Why would the update fail?
var update = {name: someName, description: someDescription};
findByIdAndUpdate(id, update, function(err, something) { ...
Here is the error, yup cannot cast null/undefined to a String but why try?
CastError: Cast to string failed for value "undefined" at path
"description"
The update is failing because, while you're setting description to not required, the update method will still look into the value of update.description if there is one defined in the update object. This is because, according to the docs:
The update field employs the same update operators or field: value
specifications to modify the selected document.
In any case, the simple way to solve this would be to check if the description value is being passed before inserting it into the update object.
var someDescription = req.body.args.description;
var update = {name: someName};
if(someDescription)
update['description'] = someDescription;
On a side note, nulls are not allowed, as stated here