Netsuite Multiple inserts of Address on Customer Record - netsuite

We are using the REST API to Upsert customer record. Included in the PUT is the address record.
Everytime we send the PUT, the customer record is updated as expected. The problem is that every time we run the request, a new address is added to the address book.
"companyName"=> $result['CLIENTNAME'],
"email"=> '',
"emailPreference"=> "PDF",
"emailTransactions"=> false,
"externalId"=> $netsuiteCustomerId,
"isinactive"=> false,
"phone"=> $result['TELEPHONENO'],
"subsidiary"=> ["id"=> "2"],
"terms"=> ["externalId"=> "PTTRM".$result["TERMID"]],
"vatRegNumber"=> $result['ABN'],
"addressbook" => array(
"items" => array(
array(
"label"=> $address['addr1'],
"addressbookaddress" => $address = array(
"addr1" => $result['ADDRESS1'],
"addressee" => $result['CLIENTNAME'],
"addrText"=> $result['ADDRESS1']."\n".$result['ADDRESS2'],
"externalId" => 'ADDR_'.$netsuiteCustomerId,
);
)
)
)
Adding the externalId to the address doesn't appear to work. We have multiple addresses with the same ID. The SOAP API allows a replaceAll attribute, but that doesn't exist on the REST API.

I haven't tried doing this myself but you may want to check the documentation again (https://docs.oracle.com/cloud/latest/netsuitecs_gs/NSTRW/NSTRW.pdf). It shows samples of replacing sublists using 'replace' in the query parameter.
The REST API browser also mentions 'replace' under request parameters.

You need to use PATCH instead of PUT to update the address

Related

Hubspot API - list of properties needed (nodejs)

I am integrating the hubspot API to track user interaction with our site. I am creating dynamic lists and I want to filter a user into a certain contact list by which URL they visit.
"filters": [
[
{
"operator": "CONTAINS",
"property": "hs_URL",
"value": `${id}`
},
],
]
I keep getting this error for all my attempts:
{"status":"error","message":"Couldn't find a Property with the given name 'hs_URL'","correlationId":"0723dcee-534b-4f92-9104-509d6885abbe","propertiesErrorCode":"PROPERTY_NOT_FOUND"},
I cannot seem to find a master property list and have tried many string combinations. Anyone familiar with hubspot property lists would be my savior.
Thank you~!
It's been a few months, so you may not need this anymore, but since I landed here while looking for a way to get all the properties from an object type in hubspot using nodejs, this might help others looking for the solution.
The master list of properties can be retrieved with the following API call:
const response = await hubspotClient.crm.properties.coreApi.getAll(objectType, false);
The arguments for getAll() expect:
objectType: a string, i.e "contacts".
archived: a boolean, i.e false. Set this true if you want to get archived properties.
The following code was adapted based on this page from the hubspot API docs:
https://developers.hubspot.com/docs/api/crm/properties
Once you're on the page, you can click on the "Endpoints" Tab to reveal code snippets for multiple environments, including nodejs.
For this example, getProperties(), retrieves all properties for a given object type. I used contacts for the object type, which I believe is where you are storing the url property, but you could use the same function to get properties for other object types such as companies or deals.
It might be worth noting that I mapped the results to return just the property names, which sounds like all you need for your case, but more information is contained in the results if you need it. Just remove this bit to get more information on each property:
.map(prop => prop.name)
const hubspot = require('#hubspot/api-client')
const hubspotClient = new hubspot.Client({ apiKey: "YOUR_API_KEY" })
const getProperties = async (objectType) => {
try {
const response = await hubspotClient.crm.properties.coreApi.getAll(objectType, false);
return response.body.results.map(prop => prop.name);
} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e);
}
}
Here's an example for running the function to get a list of all property names for contacts.
(async () => {
var properties = await getProperties("contacts");
console.log(JSON.stringify(properties ,null,2));
})();
It took me a bit to find this, so figured I would post here in the hopes it saves time for someone else. This is the first time I've posted a solution, and I'm pretty new to this API and Hubspot in general, so feedback and/or better solutions are welcome. Cheers.

Sending the same PUT request multiple times creates more entries in the database

As far as I know, with PUT one can create a resource if it doesn't exist or it is going to replace the old one with a new one.
I want to create a resource and being able to update it, not create more resources, using Node.js/Express and MongoDB.
So, I wrote this code:
app.put('/entries/:entry_id/type', (req, res) => {
const entry = new Entry (req.body);
entry.save();
res.end();
})
in Postman there is a PUT request, having the url: localhost:5000/entries/2/type
After sending it once, it creates an entry in the dabatase. All good!
But let's try to send the same request again. Now there are 2 entries in the database. I would expect to be one, because the same request was sent.
In the database they have the same data, same schema but they do have an extra field,
"_id":{"$oid":"5e8909e60c606c002axxxxxx"},, which is has the last character different.
Why are there created more entries of the same data while I was expecting to have only one entry in the database?
Mongo automatically creates a default index named _id on every collection when it is created. If you insert a Document into a collection without specifying an _id it will generate a new ObjectId as the _id field.
To get around this you can use findOneAndUpdate with upsert:
Entry.findOneAndUpdate({ entry_id: req.params.entry_id }, { <content> }, { upsert: true })
However this will update the document if it exists already instead of creating a new one. If you further wish to not change the Document at all if it already exists, then you can surround your <content> with $setOnInsert.

How do I search related values in Yii2?

I have the following situation in Yii2:
Project model
CustomField, defining a custom field type and whether it should be applied to Projects (other options are employees and companies)
CustomFieldContent, related to both an entity (project in this case) and a custom field type
So, an example:
Project with id 1
CustomField with id 2
CustomFieldContent with entityId = 1, type = 'project', customFieldId = 2 and value = 'test'
Now, displaying custom content for each project in Yii's gridview is no problem. But, I want to make it searchable and sortable. Therefore, I need to add the custom field name as an attribute to ProjectSearch. That, however, can't be done as Yii doesn't allow for dynamic attributes.
Any ideas as to how to go about this?
For searchable and sortable content i suggest you this tutorial where you can find useful sample for build what you need. ( the scenario nuber 2 is the more appropriate to your needs)
In short term, you should extend your base model adding the relation you need, setup in searchModel proper functions adding to the dataProvider->setSort for the field/relation and add the where condition for filtering.
below a short extract
$dataProvider->setSort([
'attributes' => [
....
'yourRelatedField' => [
'asc' => ['field1' => SORT_ASC, ],
'desc' => ['field1' => SORT_DESC,],
'label' => 'your Laber',
'default' => SORT_ASC
],
]
]);
and extending the where condition for filtering.
/* Add your filtering criteria */
// filter CustomFieldContent
$query->joinWith(['table_a' => function ($q) {
$q->where('table_a.CustomFieldContent LIKE "%' . $this->CustomFieldContent . '%" ');
}]);

TYPO3 backend: search custom records

I developed an extension which allows creation of new records.
In List module, under the records list, there is the Search form.
It works with fe users for example, but not with my custom records.
Is there any special configuration that I have to add in my tca to make this form work with my custom records?
EDIT: This seems to be happening after updating to TYPO3 4.6. In the previous version, 4.3.3, it works.
Thanks.
Edit ext_tables.php file in typo3conf/ext/yourext directory, find your table, and add to its ctrl section searchFields property as comma separated list of fields to search in:
$TCA['tx_yourext_table'] = array(
'ctrl' => array(
'title' => 'Title of your table',
'label' => 'title',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
// etc...
'searchFields' => 'title, other_field, yet_other_field',
),
);
Don't forget to clear all caches after that, works at 4.6.3
There's official information when and why it was changed

Kohana 3: Validation rule for has_many through relationship

Is it possible to create a validation rule in Kohana 3 that will validate the has_many through relationship?
Using the example on the guide page, a blog post can have many categories through the categories_posts table. Is there a validation rule that can be setup in the Post model to verify at least one category was added?
I tried the following:
public function rules()
{
return array(
'categories' => array(
array(array($this, 'has'), array('categories'))
)
);
}
because I see that the ORM::has function will return true/false. But I think because 'categories' is a relationship, and not a field, the rule I wrote never gets checked.
Any ideas?
You must save Post before adding has_many relations. You can check Post for categories after saving, and mark it as draft if they were not set.
Woo, good idea.
Focus in MVC design pattern. I think that's C business not the M.
if ($post->categories->find_all())
{
//blablabla
}
Since categories is external to the posts table, you'll want to use external validation. Create a function called Model_Post::rule_has_valid_categories($submitted_categories, $post) that returns a boolean denoting whether or not the submitted categories are valid for this post.
Then, create the extra rule just before you try to save the post:
$extra_rules = Validation::factory(array('categories' => $submitted_categories))
->rule(
'categories',
'Model_Post::rule_has_valid_categories',
array(':value', ':model')
);
try
{
$post->save($extra_rules);
}
catch (ORM_Validation_Exception $e)
{
// if categories rule failed, array will contain _external[categories] field
print_r($e->errors('models'));
}
You store the message in /application/messages/models/post/_external.php:
return array(
'categories' => array(
'Model_Post::rule_has_valid_categories' => 'Invalid categories'
),
);

Resources