Cannot set salesorder to fulfilled CRM 2013 - dynamics-crm-2013

I have written the following code for order fulfillment in crm 2013.
FulfillSalesOrderRequest req = new FulfillSalesOrderRequest();
req.OrderClose = new Entity();
req.OrderClose.LogicalName = "salesorder";
req.OrderClose.Id = pSalesOrderId;
OptionSetValue o = new OptionSetValue();
o.Value = 100001;
req.Status = o;
FulfillSalesOrderResponse resp = (FulfillSalesOrderResponse)_service.Execute(req);
But Order is not getting fulfilled.
Please help me if anything i am missing ?

OrderClose property is an orderclose, not a salesorder. In addition you need to set the SalesOrderId property
try with this code (assuming your status value is valid)
FulfillSalesOrderRequest req = new FulfillSalesOrderRequest();
req.OrderClose = new Entity("orderclose");
req.OrderClose["salesorderid"] = new EntityReference("salesorder", pSalesOrderId);
req.Status = new OptionSetValue(100001);
FulfillSalesOrderResponse resp = (FulfillSalesOrderResponse)_service.Execute(req);

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.

How to fetch all roles of systemuser?

I am trying to pull all roles assigned to a systemuser. I think I require to use associated entities but I am not sure how should I proceed with the approach.
Here is my code snippet:
Uri organizationUri = new Uri(this.ConnectionString);
Uri homeRealmUri = null;
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = ConfigUserName;
credentials.UserName.Password = ConfigPassword;
Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy orgProxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
IOrganizationService _service = (IOrganizationService)orgProxy;
Microsoft.Xrm.Sdk.Entity account = new Microsoft.Xrm.Sdk.Entity("systemuser");
QueryExpression query = new QueryExpression
{
EntityName = account.LogicalName,
ColumnSet = new ColumnSet(true)
};
DataCollection<Microsoft.Xrm.Sdk.Entity> users = _service.RetrieveMultiple(query).Entities;
// fetch assigned roles of users
Here is my implementation to pull all roles of specific user
QueryExpression query = new QueryExpression();
query.EntityName = "role";
query.ColumnSet = new ColumnSet(true);
LinkEntity role = new LinkEntity();
role.LinkFromEntityName = "role";
role.LinkFromAttributeName = "roleid";
role.LinkToEntityName = "systemuserroles";
role.LinkToAttributeName = "roleid";
LinkEntity userRoles = new LinkEntity();
userRoles.LinkFromEntityName = "systemuserroles";
userRoles.LinkFromAttributeName = "systemuserid";
userRoles.LinkToEntityName = "systemuser";
userRoles.LinkToAttributeName = "systemuserid";
ConditionExpression conditionExpression = new ConditionExpression();
conditionExpression.AttributeName = "systemuserid";
conditionExpression.Operator = ConditionOperator.Equal;
conditionExpression.Values.Add(userId);
userRoles.LinkCriteria = new FilterExpression();
userRoles.LinkCriteria.Conditions.Add(conditionExpression);
role.LinkEntities.Add(userRoles);
query.LinkEntities.Add(role);
DataCollection<Microsoft.Xrm.Sdk.Entity> userRoles = _service.RetrieveMultiple(query).Entities;
return userRoles;
There is a sample on the MSDN for checking users security roles, should help you finish this off.
Sample: Determine Whether a User has a Role
The following Linq query using the generated early-bound CRM entities will do what you're after:
var query = from user in context.SystemUserSet
join userRoles in context.SystemUserRolesSet on user.SystemUserId equals userRoles.SystemUserId
join role in context.RoleSet on userRoles.RoleId equals role.RoleId
where user.DomainName == '<username>'
select role;
Information on generating early-bound entities can be found here: CrmSvcUtil usage

How to set a specific picklist value on crm 4.0?

i try to set selected value of my picklist while adding a new account.My code is :
CrmService service = connectToCrm();
PropertyCollection Prop = new PropertyCollection();
DynamicEntity Firma = new DynamicEntity();
// set table
Firma.Name = EntityName.account.ToString();
StringProperty accountName = new StringProperty();
accountName.Name = "name";
accountName.Value = aDict["name"].ToString();
Prop.Add(accountName);
StringProperty vendorCode = new StringProperty();
vendorCode.Name = "new_bayikodu";
vendorCode.Value = aDict["new_bayikodu"].ToString();
Prop.Add(vendorCode);
StringProperty VD = new StringProperty();
VD.Name = "new_taxoffice";
VD.Value = aDict["new_taxoffice"].ToString();
Prop.Add(VD);
StringProperty VN = new StringProperty();
VN.Name = "accountnumber";
VN.Value = aDict["accountnumber"].ToString();
Prop.Add(VN);
StringProperty address = new StringProperty();
address.Name = "address1_line1";
address.Value = aDict["address1_line1"].ToString();
Prop.Add(address);
StringProperty tel = new StringProperty();
tel.Name = "telephone1";
tel.Value = aDict["telephone1"].ToString();
Prop.Add(tel);
StringProperty accountEmail = new StringProperty();
accountEmail.Name = "emailaddress1";
accountEmail.Value = aDict["emailaddress1"].ToString();
Prop.Add(accountEmail);
Firma.Properties = Prop;
Guid CustomerGuid = service.Create(Firma);
Example i want to set city picklist to "istanbul"
can i use a picklistproperty ?
Here is a similar question asked in SO: Setting BusinessEntity picklist value using CRM 4.0 webservice
Please note that to set a picklist property on an entity, you need to know the value of the picklist item you wish to choose. This value property is of type integer. You may need to look at the attribute schema from within CRM to get this value. Or alternatively if this customization is going to be installed in multiple organizations and you believe this value might change, then you may need to retrieve the attribute metadata and determine the correct item programmatically based on the name. (This 2nd solution is not ideal as the picklist 'name' could be updated and would therefore break your code).
PicklistProperty city = new PicklistProperty();
city.Name = "new_city";
city.Value = 23; // City Picklist Value for 'istanbul';
Prop.Add(city);
PicklistProperty city = new PicklistProperty();
city.Name = "new_city";
city.Value = new Picklist();
city.Value.Value = 23; // City Picklist Value for 'istanbul';
Then you can use 'city' to set your picklist.