QueryExpression Phonecall to Contact - dynamics-crm-2011

I've been stuck on this for a bit. Here's the scope of what I'm trying to do:
Retrieve phonecall records while bringing in contact information within the "to" field.
After much research, I have boiled down the code to below. I'm not too sure if I'm doing linked entities right - but can't determine how to do a nested join like I need to as I need to somehow get to the activitypointer -> activityparty -> contact...I just don't know where I"m going wrong. Any help would be greatly appreciated.
using Microsoft.Crm.Sdk.Messages.Samples;
using Microsoft.Xrm.Sdk.Query.Samples;
QueryExpression qExpression = new QueryExpression("phonecall")
{
ColumnSet = cs,
LinkEntities =
{
new LinkEntity()
{
EntityAlias = "ap",
LinkFromEntityName= "phonecall",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activitypointer",
LinkToAttributeName = "activityid",
JoinOperator = JoinOperator.Inner
},
new LinkEntity()
{
EntityAlias = "app",
LinkFromEntityName= "activitypointer",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
JoinOperator = JoinOperator.Inner,
LinkCriteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("ParticipationTypeMask", ConditionOperator.Equal, 2),
}
}
},
new LinkEntity()
{
EntityAlias = "con",
Columns = new ColumnSet("fullname","contactid"),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "activityparty",
LinkFromAttributeName = "partyid",
LinkToEntityName = "contact",
LinkToAttributeName = "contactid"
}
}
};

Looks like I answered my own question, giving some inspiration. I had to nest the link within a link.
This is what works now
QueryExpression qExpression = new QueryExpression("phonecall")
{
ColumnSet = cs,
LinkEntities =
{
new LinkEntity()
{
EntityAlias = "app",
LinkFromEntityName= "phonecall",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
JoinOperator = JoinOperator.Inner,
LinkCriteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("participationtypemask", ConditionOperator.Equal, 2),
}
},
LinkEntities =
{
new LinkEntity()
{
EntityAlias = "con",
Columns = new ColumnSet("fullname","contactid"),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "activityparty",
LinkFromAttributeName = "partyid",
LinkToEntityName = "contact",
LinkToAttributeName = "contactid"
}
}
},
}
};

Using DLaB.Xrm, you could re-write this like this:
var qe = QueryExpressionFactory.Create(cs, "phonecall");
var activityParty = qe.AddLink("activityparty", "activityid");
activityParty.WhereEqual("participationtypemask", 2);
activityParty.AddLink("contact", "partyid", "contactid")
.AddColumns("fullname","contactid");
Having a lot less code to look at tends to make it easier to Grok IMHO.
This is how I would read teach line of my 5 lines listed:
I'm doing a Query against the Phone Call Entity
Joining to the Activity Party on the activity Id (same key for both, no need to duplicate)
Where the activityParty's ParticipationTypeMask == 2
And joining from that to the Contact on ActivityParty.PartyId == Contact.ContactId
Including the name and Id of the contact.

Related

Acumatica API Error when creating a Inventory Receipts API calls

Good day
I am creating a SOAP contract base connection to Acumatica.
I am getting an error: "System.ArgumentNullException: Value cannot be null."
I am not sure why I am getting the error.
Here is my code
using (var soapClient = new DefaultSoapClient())
{
try
{
soapClient.Login();
InventoryReceipt NewinventoryReceipt = new InventoryReceipt
{
ReferenceNbr = new StringValue { Value = "<NEW>" },
Hold = new BooleanValue { Value = true },
Date = new DateTimeValue { Value = DateTime.Now },
PostPeriod = new StringValue { Value = DateTime.Now.ToString("DD-yyyy") },
TransferNbr = new StringValue { Value = "" },
//External Ref
Description = new StringValue { Value = "" },
Details = new InventoryReceiptDetail[]
{
new InventoryReceiptDetail
{
//branch
InventoryID = new StringValue{Value = "NIS777"},
WarehouseID = new StringValue{Value = "FBTZEST"},
Location = new StringValue {Value = "BULK"},
Qty = new DecimalValue{Value = 1},
UOM = new StringValue{Value = "PALLET"},
UnitCost = new DecimalValue{Value = 91},
ExtCost = new DecimalValue{Value = 91},
LotSerialNbr = new StringValue{Value = "PLN12345"},
ExpirationDate = new DateTimeValue{Value = DateTime.Now},
// ReasonCode
Description = new StringValue{Value = ""}
}
},
};
InventoryReceipt putInventoryReceipt = (InventoryReceipt)soapClient.Put(NewinventoryReceipt);
}
catch (Exception ex)
{
soapClient.Logout();
throw;
}
finally
{
soapClient.Logout();
}
soapClient.Logout();
}
Console.ReadLine();
}
Is there any way to see what is null or what I am missing to post this data?
Have you tried manually entering the data into the UI? The Validation on the web service should be the same as the UI, so you might get more info from the UI. You have a lot of dependent values here since you're referencing a specific Lot perhaps a value is missing. Other than that, you might try adding Project = X.

Generic List to String Conversion Using Gson in Xamarin

I new with Xamarin , I am trying to convert my list of generic type to single string. I can comfortably performs this task in Android using below code.
Gson gson = new Gson();
Type collectionType = new TypeToken<ArrayList<Response_bean>>() {}.getType();
JsonElement element = gson.toJsonTree(response_data, collectionType);
JsonArray jsonArray = element.getAsJsonArray();
String strjsonarray = jsonArray.toString();
But I cant found its replacement in Xamarin.
Please help Thanks in advance.
I think you can use json.net
Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Sizes = new string[] { "Small" };
string json = JsonConvert.SerializeObject(product);
// {
// "Name": "Apple",
// "Expiry": "2008-12-28T00:00:00",
// "Sizes": [
// "Small"
// ]
// }
As Alessandro Caliaro said, json.net can help you.
List<Product> list = new List<Product>();
Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Sizes = new string[] { "Small" };
Product product2 = new Product();
product2.Name = "Banana";
product2.Expiry = new DateTime(2010, 12, 28);
product2.Sizes = new string[] { "Big" };
Product product3 = new Product();
product3.Name = "Pear";
product3.Expiry = new DateTime(2012, 12, 28);
product3.Sizes = new string[] { "Huge" };
list.Add(product);
list.Add(product2);
list.Add(product3);
string json = JsonConvert.SerializeObject(list);
Output
[
{"Name":"Apple","Expiry":"2008-12-28T00:00:00","Sizes":["Small"]},
{"Name":"Banana","Expiry":"2010-12-28T00:00:00","Sizes":["Big"]},
{"Name":"Pear","Expiry":"2012-12-28T00:00:00","Sizes":["Huge"]}
]

How to specify fields for detail records with Acumatica ReturnBehavior

I'm trying to use the Acumatica API to return a list of Sales Order and Sales Order Details, while limiting the fields returned.
So far, I have :
SalesOrder filter = new SalesOrder
{
//Filter the SOs returned
OrderType = new AcumaticaOpticsExt.StringValue { Value = salesOrder.Split('/').First() },
OrderNbr = new AcumaticaOpticsExt.StringValue { Value = salesOrder.Split('/').Last() },
//Specify return behavior
ReturnBehavior = ReturnBehavior.OnlySpecified,
//Specify the fields to be returned on the SO
Hold = new BooleanReturn(),
CustomerName = new StringReturn(),
SchedShipment = new DateTimeReturn(),
QtyAllocatedM = new DecimalReturn(),
QtyAllocatedNotCompletedM = new DecimalReturn(),
//And from the SO Line Detail
};
It's not clear how I can specify the fields from the Details and I haven't found any multi-level uses in the documentation.
Does anyone have an example?
Here is an example that works for me :
SalesOrder so = new SalesOrder
{
ReturnBehavior = ReturnBehavior.OnlySpecified,
OrderType = new StringSearch { Value = "SO", Condition = StringCondition.Equal },
OrderNbr = new StringSearch { Value = "001253", Condition = StringCondition.Equal },
Details = new SalesOrderDetail[]
{
new SalesOrderDetail
{
ReturnBehavior = ReturnBehavior.OnlySpecified,
InventoryID = new StringReturn(),
LineNbr = new IntReturn(),
UOM = new StringReturn(),
UnitPrice = new DecimalReturn(),
Quantity = new DecimalReturn()
}
}
};
You just have to define the array of detail items, in the first one define the return behavior level that you want and if it applies the field(s) that you want to be returned.

Can't create invoice details with manual discount using OrganizationServiceClient in CRM 2011

I'm using OrganizationServiceClient with CRM 2011, When I create an invoicedetail with a manualdiscountamount, the discount doesn't appear in the CRM website.
Here's my code:
OrganizationServiceClient client = new OrganizationServiceClient("CustomBinding_IOrganizationService",new EndpointAddress(AuthenticationInfo.OrganizationServiceUrl))) { client.ConfigureCrmOnlineBinding(AuthenticationInfo.OrganizationPolicy.IssuerUri);
client.Token = AuthenticationInfo.OrganizationToken;
Entity entityDetails = = new Entity();
entityDetails.LogicalName = "invoicedetail";
entityDetails.Attributes = new AttributeCollection();
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
key = "productid",
value =
new EntityReference() {
LogicalName = "product",
Id = Guid.Parse("Some Product Id")
}
});
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
key = "uomid",
value =
new EntityReference() {
LogicalName = "uom",
Id = Guid.Parse("33B75DB8-8771-4B5A-875F-810CC0732C0C")
}
});
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
key = "invoiceid",
value = new EntityReference() {LogicalName = "invoice", Id = Guid.Parse("Some Invoice Id")}
});
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
key = "quantity",
value = 1
});
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
key = "createdon",
value = DateTime.Now
});
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
key = "manualdiscountamount",
value = 15
});
invoiceDetailsId = client.Create(entityDetails);
What may be the problem here?
Try to use following code to add manualdiscountamount field:
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
key = "manualdiscountamount",
value = new Money(Convert.ToDecimal(15))
});
Because manualdiscountamount field is of Money type. Recheck following article

Cassandra Batch_mutate()

Please Provide an example on how to work with batch_mutate() in C#.net?
Thanks in advance.
Dictionary <string, Dictionary<string, List<Mutation>>> dictionary = new Dictionary<string, Dictionary<string, List<Mutation>>>();
List<Mutation> columnsToadd = new List<Mutation>();
List<Column> customers = new List<Column>();
//List of SuperColumns
customers.Add(new Column() { Name = utf8Encoding.GetBytes("street"), Timestamp = timeStamp, Value = utf8Encoding.GetBytes("Test") });
customers.Add(new Column() { Name = utf8Encoding.GetBytes("Zip"), Timestamp = timeStamp, Value = utf8Encoding.GetBytes("Test") });
customers.Add(new Column() { Name = utf8Encoding.GetBytes("city"), Timestamp = timeStamp, Value = utf8Encoding.GetBytes("Test Hills") });
Dictionary<string, List<Mutation>> innerMap = new Dictionary<string, List<Mutation>>();
Mutation columns = new Mutation()
{
Column_or_supercolumn = new ColumnOrSuperColumn() { Super_column = new SuperColumn() { Name = utf8Encoding.GetBytes("John1"), Columns = customers } }
};
columnsToadd.Add(columns);
ColumnPath nameColumnPath = new ColumnPath()
{
Column_family = "Super1",
Super_column = utf8Encoding.GetBytes("John1"),
Column = utf8Encoding.GetBytes("customers")
};
innerMap.Add("Super1", columnsToadd);
dictionary.Add("Phatduckk", innerMap);
client.batch_mutate("Keyspace1", dictionary, ConsistencyLevel.ONE);

Resources