SAP Business One - Add BP (DI Error: (-5002) - sapb1

I am trying to add new addresses into a BP. If there is an address registered in the BP everything works, but now if it is new addresses return the error -5002 - Error updating BP: [OCRD.State2], 'the linked value' SP 'does not exist'
I test with SAP Business 10 (10.00.140) FP 2011
if (oBP.GetByKey(CardCode))
{
oBP.Addresses.SetCurrentLine(oBP.Addresses.Count - 1);
if (!string.IsNullOrEmpty(oBP.Addresses.AddressName))
{
oBP.Addresses.Add();
}
UF = json.data.endereco_uf;
if (UF.Length > 2)
{
UF = "";
}
oBP.Addresses.SetCurrentLine(oBP.Addresses.Count - 1);
oBP.Addresses.AddressName = "Novo 1";
oBP.Addresses.AddressType = BoAddressType.bo_ShipTo;
oBP.Addresses.Street = json.data.endereco_logradouro;
oBP.Addresses.Block = json.data.endereco_bairro;
oBP.Addresses.ZipCode = json.data.endereco_cep;
oBP.Addresses.City = json.data.endereco_municipio;
oBP.Addresses.State = UF;
oBP.Addresses.County = county;
oBP.Addresses.StreetNo = json.data.endereco_numero;
oBP.Addresses.BuildingFloorRoom = json.data.endereco_complemento;
oBP.Addresses.Add();
oBP.Addresses.SetCurrentLine(oBP.Addresses.Count - 1);
oBP.Addresses.AddressName = "Novo 2";
oBP.Addresses.AddressType = BoAddressType.bo_BillTo;
oBP.Addresses.Street = json.data.endereco_logradouro;
oBP.Addresses.Block = json.data.endereco_bairro;
oBP.Addresses.ZipCode = json.data.endereco_cep;
oBP.Addresses.City = json.data.endereco_municipio;
oBP.Addresses.State = UF;
oBP.Addresses.County = county;
oBP.Addresses.StreetNo = json.data.endereco_numero;
oBP.Addresses.BuildingFloorRoom = json.data.endereco_complemento;
oBP.Addresses.Add();
int iRetVal = oBP.Update();
if (iRetVal != 0)
{
Program.oApplication.StatusBar.SetText("Error updating BP: " + Program.oCompany.GetLastErrorDescription(), BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
return false;
}

SAP helped me to solve this issue. The answer follows.
I tried to reproduce this issue in the DemoUK (GB Localization) database and was able to reproduce as well.
After the investigation, it was found that you cannot link a state which does not exist for the specific country.
In your case, the system throws the error because the data is validated based on the following query:
SELECT* FROM OCST WHERE "Code" = 'SP' and "Country" = ''
Similarly, if I will try to set the State as 'Arizona' and Country as 'United Kingdom', it will give me the same error because the correct 'Country' value should be 'USA'.
Therefore, in order to resolve this issue, you need to opt out one of the following:
Set the Country property also in the DI Code (State should belong to the Country which you are trying to set):
oBP.Addresses.Country = "GB"
Remove the State property from the DI Code:
oBP.Addresses.State = "SP"

Related

how to add Customer Name

$hostedPaymentData = new HostedPaymentData();
$hostedPaymentData->customerEmail = $this->customer_email;
$hostedPaymentData->customerPhoneMobile = $this->customer_mobile_phone;
$hostedPaymentData->addressesMatch = false;
How to add customer name in hosted payment data
The following all work, the comments are the POST variables they populate when requesting the HPP.
// HPP_NAME
$hostedPaymentData->customerName = 'asdf hjkl';
// HPP_CUSTOMER_FIRSTNAME
$hostedPaymentData->customerFirstName = 'asdf';
// HPP_CUSTOMER_LASTNAME
$hostedPaymentData->customerLastName = 'hjkl';

Salesforce first error: INVALID_CROSS_REFERENCE_KEY, Entity not available

When I am trying to run my test class I am getting the below error.
System.DmlException: Update failed. First exception on row 0 with id 8023B000000ekyaQAA; first error: INVALID_CROSS_REFERENCE_KEY, Entity not available: [PricebookEntryId]
Also in the stack trace of debug log I am getting the below message
Class.OBOrderLineItemCreate.updateObjectMethod: line 367, column 1
I have Created the product and referenced the Standard price book. And have created the Pricebookentry, Order and Order line item. I am not sure why I am getting this error. Can anyone please help me with this and let me know what am I doing wrong? Thanks in advance.
My test class code is as below
Product2 prod = new Product2();
prod.Name = 'Inb Enterprise';
prod.Description = 'Annual subscription,80 topics, 40,000 company locations';
prod.productCode = 'ABC';
prod.Service_Type__c = 'Inb';
prod.OB_Sub_Type_Name__c = 'Inb';
prod.isActive = true;
insert prod;
Pricebook2 standardPricebook = new Pricebook2(
Id = Test.getStandardPricebookId(),
IsActive = true
);
update standardPricebook;
standardPricebook = [SELECT Id, IsStandard FROM Pricebook2 WHERE Id = :standardPricebook.Id];
//Id pricebookId = Test.getStandardPricebookId();
//Test.startTest();
PricebookEntry standardPrice = new PricebookEntry();
standardPrice.Pricebook2Id = standardPricebook.Id;
standardPrice.Product2Id = prod.Id;
standardPrice.UnitPrice = 10000;
standardPrice.IsActive = true;
insert standardPrice;
Order ord = new Order();
ord.Name = 'Test Order';
ord.AccountId = acc.Id;
ord.Pricebook2Id = standardPricebook.Id;
ord.Customer_Success_Manager__c = am.Id;
ord.Agency_Name__c = agc.Id;
ord.OpportunityId = opp.Id;
ord.Purchase_Order__c = '783983';
ord.EffectiveDate = Date.today();
ord.Status = 'Draft';
ord.OBSyncStatus__c = 'Inactive';
ord.End_Date__c = Date.today();
insert ord;
OrderItem oli = new OrderItem();
oli.OrderId = ord.Id;
oli.PricebookEntryId = standardPrice.Id;
oli.Quantity = 5;
oli.UnitPrice = 35;
oli.OBSyncStatus__c = 'Inactive';
oli.Line_Item_Start_Date__c = Date.Today();
oli.Line_Item_End_Date__c = Date.Today();
oli.Bonus_Units__c = 25;
oli.Geography__c = 'US';
oli.Unique_Line_Item_Name__c = 'Inb Order';
insert oli;
You don't need the code of instantiating the Pricebook2 object. Get rid of that code and use the code below.
standardPrice.Pricebook2Id = Test.getStandardPricebookId().
Do the same for ord.Pricebook2Id also.

LINQ - query Where method error

I have the following code that I cannot make it work.
I am new using Linq and Entity framework.
I attach the code sample, and also, and image with the error.
What I am trying to do, is a piece of code where I can add "Where"s dynamically.
Imports System.Linq
Private cntx As New attmanager_bdEntities()
Dim query = (From persona In cntx.tblperson
Select
ATT_TYPE = persona.att_type,
ATT_RECOG = persona.att_recog,
APELLIDO = persona.surname,
NOMBRE = persona.name,
PERSONA_ID = persona.id,
DNI = persona.identification,
DIRECCION = persona.address,
PIN = persona.att_pin,
TIPOASISTENCIA = persona.att_type,
EMAIL = persona.email,
EXTRA = persona.extra,
TELEFONO = persona.phone,
FECHANACIMIENTO = persona.birth,
SEXO = persona.sex,
DELETED = persona.deleted,
AREA_ID = persona.tblarea.id,
AREA = persona.tblarea.name,
CIUDAD = persona.tblcity.name,
CIUDAD_ID = persona.tblcity_id,
PROVINCIA = persona.tblcity.tblstate.name,
PAIS = persona.tblcity.tblstate.tblcountry.name
Where (DELETED = 0))
query = query.Where(Function(a) a.AREA_ID = 1)
'Here I should put another "Where"s
dbgrid_listado.DataSource = query.ToList()
Error translation:
Unexpected exception trying to load "personas"
Details:
Could not invoke the method because could not call a 'Public Function Where ..........
......
......
......
...... with those arguments.
The parameter 'predicate' of the argument could not be converted to VB$AnonymousDelegate_0(Of Object,Object)' into 'String'
Why not this?
Dim query = (From persona In cntx.tblperson
Where persona.DELETED = 0
Select persona)
Now your type is "persona" instead of an anonymous type of 21 random properties.
query = query.Where(Function(a) a.AREA_ID = 1)
Working with anonymous types is always tricky. Also, I always put the select last...
You could always list out the properties in an anonymous type like this:
Dim query = (From persona In cntx.tblperson
Where persona.DELETED = 0
Select New With {
ATT_TYPE = persona.att_type,
ATT_RECOG = persona.att_recog,
APELLIDO = persona.surname,
NOMBRE = persona.name,
PERSONA_ID = persona.id,
DNI = persona.identification,
DIRECCION = persona.address,
PIN = persona.att_pin,
TIPOASISTENCIA = persona.att_type,
EMAIL = persona.email,
EXTRA = persona.extra,
TELEFONO = persona.phone,
FECHANACIMIENTO = persona.birth,
SEXO = persona.sex,
DELETED = persona.deleted,
AREA_ID = persona.tblarea.id,
AREA = persona.tblarea.name,
CIUDAD = persona.tblcity.name,
CIUDAD_ID = persona.tblcity_id,
PROVINCIA = persona.tblcity.tblstate.name,
PAIS = persona.tblcity.tblstate.tblcountry.name
})
Maybe the where clause using the anon type is messing it up and using persona.DELETED = 0 would help?
I got it ....
I created a new project
I migrate all the resources (images for example) from the old project to this new one.
Opened the NuGet package manager, and installed EF6
Also installed MySQL.Data and MySQL EF6 provider.
I imported the forms, from the original project to the new one.
Now I can do what you guys suggested.
The Problem ??? .... The version on .Net framework, and the EF I was using.
I had t update everything.

MapKit: How to retrieve apartment number from the return value of MKLocalSearchResponse

I searched thoroughly online but couldn't find any discussion about this:
The MKLocalSearchResponse object returned from a MapKit search is a collection of MKMapItem, which has the information of search results, e.g. City, state, country.
A single MKMapItem looks like this(from Xcode quick look of the object):
"Name: ADVANCED SOLUTIONS ADDICTION MANAGEMENT CurrentLocation: 0 Place: <GEOPlace: 0x9b2db90> {
address = {
formattedAddressLine = (
\"205 W Crestway Ave\",
\"Unit 200\",
\"Derby, KS 67037-1850\",
\"United States\"
);
structuredAddress = {
administrativeArea = Kansas;
administrativeAreaCode = KS;
country = \"United States\";
countryCode = US;
dependentLocality = (
Derby,
Rockford
);
fullThoroughfare = \"205 W Crestway Ave\";
geoId = (
);
locality = Derby;
postCode = 67037;
postCodeExtension = 1850;
postCodeFull = \"67037-1850\";
subAdministrativeArea = Sedgwick;
subLocality = Rockford;
subPremise = (
{
name = 200;
type = 0;
}
);
subThoroughfare = 205;
thoroughfare = \"W Crestway Ave\";
};
};
}"
I was able to retrieve all the information I needed, except the Apartment number. It's contained in the "subPremise" part, which I don't know how to retrieve.
You may suggest me to retrieve it from the "formattedAddressLines", which I have access to, but for some results, that property is empty, so I cannot rely on it.
I've also tried the "addressDictionary" property, it has all the necessary information except apartment number, which is very unthoughtful to me.
mapItem.placemark.subThoroughfare. Note that it may be empty

Recipe for adding Drupal node records

I am looking for a recipe for adding Drupal node records.
I have identified three tables.
node_revisions
nid=249 - vid + 1?
vid=248 - auto-increment
node:
nid=250 - vid + 1?
vid=249 - auto-increment
content_type_my_content
vid=248 - from node_revisions table?
nid=249 - from node table?
Am I on right track?
Is there some helper functions for this?
If you are looking to programatically create nodes, use the Drupal API.
Start by creating a $node object. Fill in title, type, status, body, plus any CCK fields. At the end, call node_save($node);.
node_save will save your node object and do the necessary database work.
Check this out:
http://api.drupal.org/api/function/node_save/6
http://mediumexposure.com/how-build-node-drupal-programmatically/
The easiest way to see what each type of content type has as fields is to create a node (for example, Page), then use var_dump() to see the node's contents. That will show you every field you will need to use in your node object creation script.
Some folks will say you should create a form array, and call drupal_execute() on it so validation is performed before it's saved to the database. Either way is fine.
Kevin - With your help I have made good progress.
Node and CCK fields are now being populated.
Location (long/lat) is populated but not showing up on View screen.
Checkboxes are not being populated.
global $user;
$newnode = new stdClass();
$newnode->title = 'New node title';
$newnode->body = "this is a new node, created by import function";
$newnode->uid = $user->uid;
$newnode->type = 'items';
$newnode->status = 1;
$newnode->promote = 0;
// CCK fields
$newnode->field_myfield1[0]['value'] = 'test 1';
$newnode->field_myfield2[0]['value'] = 'test 2';
$newnode->field_mycheckbox[0]['value'] = 1;
// longitude, lalitude
// $newnode->locations[0]['lid'] = ?;
$newnode->locations[0]['street'] = 'xx';
$newnode->locations[0]['city'] = 'xx';
$newnode->locations[0]['province'] = 'xx';
$newnode->locations[0]['postal_code'] = 'xx';
$newnode->locations[0]['latitude'] = 0;
$newnode->locations[0]['longitude'] = 0;
$newnode = node_submit($newnode);
node_save($newnode);
content_insert($newnode);
OK. here is the full recipe. Drupal does the rest automagically.
global $user;
// Node fields
$newnode = new stdClass();
$newnode->title = $data[0];
$newnode->body = $data[1];
$newnode->uid = $user->uid;
$newnode->type = 'mytype';
$newnode->status = 1;
$newnode->promote = 0;
// CCK fields
$newnode->field_myfield1[0]['value'] = $something;
$newnode->field_myfield2[0]['value'] = $something;
$newnode->field_my_checkbox[0]['value'] = $something;
// longitude, latitude
$newnode->field_loc_latitude[0]['street'] = $something;
$newnode->field_loc_latitude[0]['city'] = $something;
$newnode->field_loc_latitude[0]['province'] = $something;
$newnode->field_loc_latitude[0]['postal_code'] = $something;
$newnode->field_loc_latitude[0]['latitude'] = '';
$newnode->field_loc_latitude[0]['longitude'] = '';
$newnode = node_submit($newnode);
node_save($newnode);
content_insert($newnode);