Asana: update custom field value with Node - node.js

I'm trying to change the value of a custom task using the Asana package for NodeJS. Sadly the official developer documentation appears to be out of date, because the updateCustomField method in the example is not valid anymore.
It looks like custom_fields can now be passed to the task.update method, but I run into 'Invalid request errors' when trying this.
Thanks!

It is indeed part of the task.update method. In the data for this method, you can set the custom_fields property to an object, where the key is the GID for the custom field you want to change and the value is the value you want to change to.
Which looks something like this:
client.tasks.update(taskID, {
custom_fields: {
"1234": "New value for field"
},
name
})

Related

Netsuite Invalid API usage. You must use getValue to return the value set with setValue

So I have an odd issue, When I create a new transaction and save, this error in the title gets thrown. But when I edit this transaction after it was created, the getText does not throw this error. Is there something I'm doing wrong or something special needed to getText on a create new record? Here is my code. This is for the afterSubmit method on my User Event Script for Vendor Bill screen. I just noticed getValue does work on create, does not produce this error, just don't understand why? Is this the correct way to get the value on create? To use getValue and getText cannot be used on create? Only for edit?
if (scriptContext.type == scriptContext.UserEventType.CREATE ||
scriptContext.type == scriptContext.UserEventType.EDIT) {
// get bill to index
var Bill = scriptContext.newRecord;
// fails on this call below on create but works on edit
var refno = Bill.getText({ fieldId: 'tranid' });
}
This behavior is described in the API documentation here.
In dynamic mode, you can use getText() without limitation but, in standard mode, limitations exist. In standard mode, you can use this method only in the following cases:
You can use getText() on any field where the script has already used setText().
If you are loading or copying a record, you can use getText on any field except those where the script has already changed the value by using setValue().
Apparently the newRecord object falls under the second criteria. At this point, the object only has values set. tranid will have a value with the transaction's internal ID, but it won't have the transaction name stored. To get the text, you will have to use record.load() to get the full record, or use search.lookupFields() to get just the transaction name.

How can I send an object as a query and use the $all operator in MERN stack?

I'm trying to make a filtering system for my web app using MERN stack. Currently I'm able to take in the user's requests for what to filter, take in that data, see which ones the user entered (because the user can also specify "Any" in a specific category, which means it would send an empty string or array to the backend), parse that data and turn it into one final object called request which would look something like this if a user decided to select SDG 8: Decent Work & Economic Growth as the SDG, Any as the assignment type, and Economy, People as the themes:
{
sdg: 'SDG 8: Decent Work & Economic Growth',
theme: [ 'Economy', 'People' ]
}
As you can see, the assignment_type value is not there because my backend code sees that they chose Any as the value and it returned an empty string which means I don't add it to my final request object.
So now that I have this object, I want to be able to send it to the database and return the objects that contain all of this information. I want to use the $all query statement for this because I need to make sure that if a user enters 'Economy', 'People' as the themes, an object that contains the themes 'Economy', 'People', 'Technology' also gets returned because the themes the user entered exists within that.
This is what I've tried so far in my test code but it doesn't seem to be working:
var request = {
sdg: 'SDG 8: Decent Work & Economic Growth',
theme: [ 'Economy', 'People' ]
}
const test = await Project.find( {$all: {request}}).sort({ createdAt: -1 })
console.log(test)
The code above just returns all values in my database and not the one's I've tried specifying. The main reason why I'm doing it this way is because I have to filter through the requests the user made in the backend in terms of which ones the user wanted specific values for, the user could specify "Any" for all 3 categories (sdg, theme, assignment_type) which would mean that the request object would just be empty so essentially I'd just be finding every single object in the database which is exactly what I want.
I'm not sure how I could make it so that I send these requests to the backend so it only finds those objects. I would appreciate some help

"code": "6140" Duplicate Document Number Error

I am using QuickBooks. Somehow I am getting some weird error on creating one invoice.
{
"Fault": {
"Error": [
{
"Message": "Duplicate Document Number Error",
"Detail": "Duplicate Document Number Error : You must specify a different number. This number has already been used. DocNumber=O0010714 is assigned to TxnType=Invoice with TxnId=45823",
"code": "6140",
"element": ""
}
],
"type": "ValidationFault"
},
"time": "2020-12-15T04:54:25.476-08:00"
}
Why it is happening as there is no doc in the QuickBooks which says that doc number is a unique entity.
Short version: DocNumber should be unique in most cases. In some cases you can add include=allowduplicatedocnum arg in URL to allow that. Be aware that DocNumber can be automatically generated.
Long version: taken from DocNumber field documentation for Invoice
Reference number for the transaction. If not explicitly provided at
create time, this field is populated based on the setting of
Preferences:CustomTxnNumber as follows:
If Preferences:CustomTxnNumber is true a custom value can be provided.
If no value is supplied, the resulting DocNumber is null.
If Preferences:CustomTxnNumber is false, resulting DocNumber is system
generated by incrementing the last number by 1.
If Preferences:CustomTxnNumber is false then do not send a value as it
can lead to unwanted duplicates. If a DocNumber value is sent for an
Update operation, then it just updates that particular invoice and
does not alter the internal system DocNumber.
Note: DocNumber is an
optional field for all locales except France. For France locale if
Preferences:CustomTxnNumber is enabled it will not be automatically
generated and is a required field. If a duplicate DocNumber needs to
be supplied, add the query parameter name/value pair,
include=allowduplicatedocnum to the URI.
P.S. Late response, but may be useful for somebody in future.
UPD:
Looks like library from npm node quickbooks doesn't support that natively. Because method createBill doesn't allow to provide any params to URI. Even method module.create have just hardcoded url variable without ability to provide nothing extra.
In this case, if you still want to use include=allowduplicatedocnum, you have the following options:
monkey-patch this library;
make fork and do updates;
ask authors of that library to implement that instead of you;
find a library that will support that;
send raw requests to QBO from your code.

Active Directory/Ldap Get DataType or Syntax of specific attributes in NodeJS

I am able to query active-directory/ldap to get the user information along with custom attributes. However I would to know the underlying DataType/attributeSyntax for each of those attribute returned.
Another the problem is that the query will not return the attribute itself if it does not contain any value.
So if can get fetch the attributes and their respective DataTypes then it provides me flexibility to set a default value basing on the DataType while preparing the final output object.
Eg:
1. I query AD to find foo user with attributes givenName, mail, myCustom1, myCustom2
{
givenName : "foo foo",
mail : "foo#boo.com",
myCustom1 : "TRUE"
}
but may not contain myCustom2 because it is not holding the value in AD.
get syntax for attributes givenName, mail, myCustom1, myCustom2
{
givenName : unistring,
mail : unistring,
myCustom1 : boolean,
myCustom2 : integer,
}
using above I can map the first result and prepare the final object as
{
givenName : "foo foo"
mail : "foo#boo.com"
myCustom1 : "TRUE"
myCustom2 : //usingHelperFunctionGetDefaultValueFor -> myCustom2
}
Active Director does not return attributes that do not have values, so that's not just the LDAPjs library, that's just how AD works.
Every object has an attribute called allowedAttributes that will show you every valid attribute that the object can potentially have.
If you need it, allowedAttributesEffective will list every attribute that the current user has permissions to modify.
These are both constructed attributes, meaning you have to ask for them specifically, or else you won't get them. For example, when searching, you have the option to specify the attributes you want to get back. If you specify nothing, you will get every non-constructed attribute that has a value. If you want any constructed attributes, you have to add it specifically to that list.
That's just a list of attributes. It won't tell you the type. You have to look to the schema for that, which is more difficult. You have to do a search using the base DN of CN=Schema,CN=Configuration,DC=domain,DC=com, where "domain.com" is the root domain of your forest, which may or may not be the same as the domain you're searching. You could look at the subSchemaSubEntry attribute of any object to find the location of the schema, although it will usually be CN=Aggregate,CN=Schema,CN=Configuration,DC=domain,DC=com (note the added CN=Aggregate).
But anyway, each object in there will have an attribute called ldapDisplayName, which is the name of the attribute as it appears on objects.
So if you want to find details on the givenName attribute, you would search the schema for (ldapDisplayName=givenName). Then the oMSyntax attribute is an enum that will tell you the type. The enum values are shown here. For givenName, that would be 64, which is a Unicode string.
The only benefit to looking up the types like this is if you are expecting your code to be run on any AD environment. If your code will only ever be run in one environment, then you can save coding time and run time by just hard-coding the attributes you are looking for and their types.

How to remove id from select active record?

Query on console
User.select('email','dob')
returns,
[#<User:0x000000084a9b08 id: nil, email: "xyz#zyx.com">,
Why am I getting id attributes in rails 4? How to get rid of this?
Pluck only returns the values if you want keys and values then
try this:
User.select('email','dob').as_json(:except => :id)
In my case the desired result was a JSON object. So, inside the as_json method
you can exclude any column you desire
(additionally you can invoke object methods or access associated tables as well)
This will give you desired output
User.pluck(:email, :dob)

Resources