This is my case, I want to pull the Vendor Credit that have ApplyList.apply.doc (this is Vendor Bill ID) in a List of Vendor Bill ID.
I have to create a TransactionSearch, but I don't know how to apply a condition for this.
For now, I just know to create a search with Status, Type, but that's not enough.
Here is my code :
var transactionsSearch = new TransactionSearch
{
basic = new TransactionSearchBasic
{
//we only want credits with an "Open" status
billingStatus = new SearchBooleanField
{
searchValue = isOpen,
searchValueSpecified = true
},
//only search for those with a type of "_vendorCredit"
type = new SearchEnumMultiSelectField
{
#operator = SearchEnumMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new[] { "_vendorCredit" }
},
}
};
I figured out the answer.
I have to use property Applied To Transaction in TransactionSearchBasic, that will be an array of Record Ref.
Related
I have a problem; I have various (too many) classes, that are linked as Parent/Child
I populate initially my top class while instantiate the others, as follows (works):
TopClass MyClass = new TopClass()
{
Headers = new someHeaders()
{
CorrID = "1234567890",
RequestID = "1234567890",
L_Token = "abcdefghijklmnopqrstuvwxyz"
},
Body = new someBody()
{
access = new AccessHeaders()
{
allPs = "allAcc",
availableAcc = "all"
},
CombinedServiceIndicator = false,
FrequencyPerDay = 10,
ValidUntil = "2020-12-31"
},
ResponseAttributes = new ConsentResponse()
{
myId = String.Empty,
myStatus = String.Empty,
myName = String.Empty,
_links_self_href = String.Empty,
status_href = String.Empty
}
};
The initials values that I populate above rarely change, but the Classes' properties change as the project goes on, and each class ends up having many properties.
I need to parse the properties and set values to any properties that match their name, but I can't seem to figure out why despite following official examples.
(I read the input data from a JSON string I use Newtonsoft - have tried everything out there)
I can't find a way to deserialize the JSON and assign any values to my properties without using the name of the property, i.e. without saying
MyClass.Body.access.allPs = "Hello"
but something like
var json = response.Content.ReadAsStringAsync().Result.ToString();
var a = new { serverTime = "", data = new object[] { } };
var c = new JsonSerializer();
or
if (myresponse.Attributes.GetType().GetTypeInfo().GetDeclaredProperty(key) != null)
myresponse.GetType().GetTypeInfo().GetDeclaredProperty(key).SetValue(myresponse, entry.Value);
//and how do I read the value, parse my TopClass and assign the value to correct property?
Could someone help me?
Values for the properties will get automatically assigned if the JSON is having the correct structure as per the class mentioned above.
Something like:
{
"Body":
"access:
{
"allPs" = "required value"
}
}
Then you can use:
var result = JsonConvert.DeserializeObject < TopClass > (json );
When data from a device goes into the elastic there are duplicates. I like to avoid this duplicates. I'm using a object of IElasticClient, .NET and NEST to put data.
I searched for a method like ElasticClient.SetDocumentId(), but cant find.
_doc doc = (_doc)obj;
HashObject hashObject = new HashObject { DataRecordId = doc.DataRecordId, TimeStamp = doc.Timestamp };
// hashId should be the document ID.
int hashId = hashObject.GetHashCode();
ElasticClient.IndexDocumentAsync(doc);
I would like to update the data set inside the Elastic instead of adding one more same object right now.
Assuming the following set up
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.DefaultIndex("example")
.DefaultTypeName("_doc");
var client = new ElasticClient(settings);
public class HashObject
{
public int DataRecordId { get; set; }
public DateTime TimeStamp { get; set; }
}
If you want to set the Id for a document explicitly on the request, you can do so with
Fluent syntax
var indexResponse = client.Index(new HashObject(), i => i.Id("your_id"));
Object initializer syntax
var indexRequest = new IndexRequest<HashObject>(new HashObject(), id: "your_id");
var indexResponse = client.Index(indexRequest);
both result in a request
PUT http://localhost:9200/example/_doc/your_id
{
"dataRecordId": 0,
"timeStamp": "0001-01-01T00:00:00"
}
As Rob pointed out in the question comments, NEST has a convention whereby it can infer the Id from the document itself, by looking for a property on the CLR POCO named Id. If it finds one, it will use that as the Id for the document. This does mean that an Id value ends up being stored in _source (and indexed, but you can disable this in the mappings), but it is useful because the Id value is automatically associated with the document and used when needed.
If HashObject is updated to have an Id value, now we can just do
Fluent syntax
var indexResponse = client.IndexDocument(new HashObject { Id = 1 });
Object initializer syntax
var indexRequest = new IndexRequest<HashObject>(new HashObject { Id = 1});
var indexResponse = client.Index(indexRequest);
which will send the request
PUT http://localhost:9200/example/_doc/1
{
"id": 1,
"dataRecordId": 0,
"timeStamp": "0001-01-01T00:00:00"
}
If your documents do not have an id field in the _source, you'll need to handle the _id values from the hits metadata from each hit yourself. For example
var searchResponse = client.Search<HashObject>(s => s
.MatchAll()
);
foreach (var hit in searchResponse.Hits)
{
var id = hit.Id;
var document = hit.Source;
// do something with them
}
Thank you very much Russ for this detailed and easy to understand description! :-)
The HashObject should be just a helper to get a unique ID from my real _doc object. Now I add a Id property to my _doc class and the rest I will show with my code below. I get now duplicates any more into the Elastic.
public void Create(object obj)
{
_doc doc = (_doc)obj;
string idAsString = doc.DataRecordId.ToString() + doc.Timestamp.ToString();
int hashId = idAsString.GetHashCode();
doc.Id = hashId;
ElasticClient.IndexDocumentAsync(doc);
}
If I have a GUID for a record, but I do not know whether it is an Account or a Contact, how can I retrieve this record and identify its type?
For example, I can retrieve a specified type like so:
var serviceAppointment = organizationService.Retrieve(
"serviceappointment",
serviceActivityGuid,
new ColumnSet(true));
However, if I do not know what type of record it is, how can I retrieve it and identify its type?
Something like this:
var myEntity = organizationService.Retrieve(
"????",
myEntityGuid,
new ColumnSet(true));
If you reference the DLaB.Xrm from Nuget, you could write this like this:
bool isAccount = service.GetEntitiesById<Account>(customerId).Count == 1;
If you wanted to actually get the actual values, you could do this.
var customerId = System.Guid.NewGuid();
var entity = service.GetEntitiesById<Account>(customerId).FirstOrDefault() ??
service.GetEntitiesById<Contact>(customerId).FirstOrDefault() as Entity;
if (entity != null)
{
var account = entity as Account; // will be null if the Guid was for a contact
var contact = entity as Contact; // will be null if the Guid was for an account
}
You cannot search by the GUID alone.
You need both the GUID and the entity logical name.
Whenever you retrieve a entity reference using code, c# or javascript, the object will include the entity logical name
Update to try to find an account with a given ID:
Guid Id = // Your GUID
IOrganizationService serviceProxy = // Create your serivce proxy
var accountQuery = new QueryExpression
{
EntityName = "account",
TopCount = 1,
Criteria =
{
Conditions =
{
new ConditionExpression("accountid", ConditionOperator.Equal, Id)
}
}
}
var response = serviceProxy.RerieveMultiple(accountQuery);
if(null == response.Entities.FirstOrDefault())
{
//No Account Record Found
}
If you only need to distinguish between with Account and Contact and want to make sure the record really still exists, you could also use their CustomerAddress, LEFT OUTER JOINing both, Account and Contact:
var query = new QueryExpression
{
EntityName = "customeraddress",
ColumnSet = new ColumnSet("customeraddressid"),
TopCount = 1,
Criteria = new FilterExpression
{
Conditions =
{
// limit to Address 1
new ConditionExpression("addressnumber", ConditionOperator.Equal, 1),
// filter by "anonymous" GUID
new ConditionExpression("parentid", ConditionOperator.Equal, myEntityGuid),
},
},
LinkEntities =
{
new LinkEntity
{
EntityAlias = "acc",
Columns = new ColumnSet("name"),
LinkFromEntityName = "customeraddress",
LinkFromAttributeName = "parentid",
LinkToAttributeName = "accountid",
LinkToEntityName = "account",
JoinOperator = JoinOperator.LeftOuter
},
new LinkEntity
{
EntityAlias = "con",
Columns = new ColumnSet("fullname"),
LinkFromEntityName = "customeraddress",
LinkFromAttributeName = "parentid",
LinkToAttributeName = "contactid",
LinkToEntityName = "contact",
JoinOperator = JoinOperator.LeftOuter
},
},
};
... will allow you to retrieve whichever, Account or Contact in one go:
var customer = service.RetrieveMultiple(query).Entities.FirstOrDefault();
... but require to access their fields through AliasedValues:
string customername = (customer.GetAttributeValue<AliasedValue>("acc.name") ?? customer.GetAttributeValue<AliasedValue>("con.fullname") ?? new AliasedValue("whatever", "whatever", null)).Value as string;
... which can make reading a lot of attributes a little messy.
I know this is an old question, but I thought I would add something in case someone stumples upon this in the future with a problem similar to mine. In this case it might not be particularly the same as OP has requested.
I had to identify whether an entity was one or the other type, so I could use one method instead of having to write standalone methods for each entity. Here goes:
var reference = new EntityReference
{
Id = Guid.NewGuid(),
LogicalName = "account" //Or some other logical name - "contact" or so.
}
And by passing it into the following method the type can be identified.
public void IdentifyType(EntityReference reference)
{
switch(reference.LogicalName)
{
case Account.EntityLogicalName:
//Do something if it's an account.
Console.WriteLine($"The entity is of type {nameof(Account.EntityLogicalName)}."
case Contact.EntityLogicalName:
//Do something if it's a contact.
Console.WriteLine($"The entity is of type {nameof(Contact.EntityLogicalName)}."
default:
//Do something if neither of above returns true.
Console.WriteLine($"The entity is not of type {nameof(Account.EntityLogicalName)} or {nameof(Contact.EntityLogicalName)}."
}
}
My problem is that after creating an invoice, I can never get new line items to reference their corresponding sales order line item.
I have been generating invoices via SuiteTalk. When I initially create an invoice, I empty the lineItemList and add back in the items I need. I make sure the orderLine property matches the sales order line item line number. This works great.
But when I try and update the invoice with additional line items, I can never get the new items to retain their orderLine property. The orderLine property is used for the "Invoiced" column on the Sales Order.
In order to get the referencing to be correct, I need to delete the invoice and create it again with all of the line items I need.
Does anyone know if what I am trying to do is possible?
In this example, I use this CreateInvoice function to create the invoice from scratch and add it to NetSuite. Everything works as expected.
public void CreateInvoice(SalesOrder salesOrder) {
Invoice brandNewInvoice = new Invoice() {
createdFrom = new RecordRef() {
internalId = salesOrder.internalId,
},
entity = salesOrder.entity,
tranDate = endDate,
tranDateSpecified = true,
startDate = startDate,
startDateSpecified = true,
endDate = endDate,
endDateSpecified = true,
itemList = new InvoiceItemList(),
};
invoice.itemList.item = GetInvoiceItemList(salesOrder); //see the function shown further down
netSuiteService.add(brandNewInvoice);
}
In this example, the invoice is already created and so I get it from NetSuite and then replace the existing itemList with a new one. After the update, the invoice will now have NO orderLine property for any of the line items. The invoice also loses its "Created From" field because there are no line items with the orderLine property set.
public void UpdateInvoice(SalesOrder salesOrder, String invoiceInternalId) {
Invoice invoice = GetNetSuiteInvoice(invoiceInternalId);
invoice.itemList.item = GetInvoiceItemList(salesOrder); //see the function shown further down
netSuiteService.update(invoice);
}
this is the function used to create the itemList:
public InvoiceItem[] GetInvoiceItemList(SalesOrder salesOrder) {
InvoiceItem[] invoiceItemList = new InvoiceItem[salesOrder.itemList.item.Length];
for (int i = 0; i < salesOrder.itemList.item.Length; i++) {
SalesOrderItem soItem = salesOrder.itemList.item[i];
double quantity = 1;
invoiceItemList[i] = new InvoiceItem() {
item = new RecordRef() {
internalId = soItem.item.internalId,
name = soItem.item.name,
},
amount = quantity * Double.Parse(soItem.rate),
amountSpecified = true,
quantity = quantity,
quantitySpecified = true,
price = new RecordRef() {
internalId = soItem.price.internalId,
name = soItem.price.name,
},
rate = soItem.rate,
orderLine = soItem.line, //this will establish the link between the invoice and the sales order
orderLineSpecified = true,
taxRate1 = soItem.taxRate1,
taxRate1Specified = true,
};
}
return invoiceItemList;
}
Actually what you are looking for is the intialize operation. You need to use initialize in order for Netsuite to properly fill in the created from and orderline props. From the NS Help there is a C# example of creating a Cash Sale:
private void Initialize()
{
this.login(true);
InitializeRef ref1 = new InitializeRef();
ref1.type = InitializeRefType.salesOrder;
//internal id of the sales order to be converted to cash sale
ref1.internalId = "792";
ref1.typeSpecified = true;
InitializeRecord rec = new InitializeRecord();
rec.type = InitializeType.cashSale;
rec.reference = ref1;
ReadResponse read1 = _service.initialize(rec);
}
This is normal, when transforming a transaction to another transaction (e.g. SO to Inv, PO to IR). When you transform, most of the information from the source transaction will be carried over. Like what you are doing which is creating an Invoice from Sales Order(Base on your code below).
createdFrom = new RecordRef() {
internalId = salesOrder.internalId,
},
You don't need to get the line item information from the Sales Order and put it in the Invoice because it will be pre-populated once you create it form Sales Oder(unless you need to change a value of a line item column).
One behavior of a transformed record(Invoice in your case), if you remove a line item from the Invoice you will lose the link to the Sales order(orderLine) and if you remove all the line item you will totally lose the link between the two transactions (createdfrom). This is what you are experiencing. orderLine/createdFrom is a field populated by the system, it looks like you are populating it but you are not.
I'm trying to create the service/product type in the invoice line item. It returns an error saying bad request, is my ItemRef phrased correctly. My service/product is created in qbo already, its called Subscription Fee, it's the 3rd in the dropdown list.
line.AnyIntuitObject = new Intuit.Ipp.Data.SalesItemLineDetail()
{
ItemRef = new Intuit.Ipp.Data.ReferenceType()
{
Value = "3",
type = "Item",
name = "Subscription Fee"
},
ItemElementName = Intuit.Ipp.Data.ItemChoiceType.UnitPrice,
AnyIntuitObject = (decimal)item.Rate, // Line item rate
Qty = (decimal)item.Quantity,
QtySpecified = true,
ServiceDate = DateTime.Now.Date,
ServiceDateSpecified = true,
TaxCodeRef = new Intuit.Ipp.Data.ReferenceType()
{
Value = taxCode0ZR.Id,
type = Enum.GetName(typeof(Intuit.Ipp.Data.objectNameEnumType), Intuit.Ipp.Data.objectNameEnumType.TaxRate),
name = taxCode0ZR.Name
},
};
What am i creating wrongly please help.
You cannot create an Item within an invoice or rather any entity within an entity.
QBO v3 does not supports creating entities on the fly.
You first need to do a create Item.
Get the Id of that Item and refer it in your Invoice.
Also, enable request/response log to get the details of the errors in log files-
https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0150_ipp_.net_devkit_3.0/0002_configuration/override_configuration