How do I update address composite in MS CRM? - c#

Problem
I am trying to get my accounts to update the composite address with the new address. Al the fields in the customer address show the new values but the composite address shows the old address.
Desired Result:
Composite field updates to the new address upon changing the address fields
Actual Result:
Composite field shows the old address
Things I've Tried:
Updating the address
Deleting The Address and creating a new one (BAD IDEA)
Setting all fields to the default values when the account was created
Setting the composite field directly
Setting the version number to the default 0x00003F3F
Setting all address fields to null
Current Code:
Entity theAccount = proxy.Retrieve("account", Guid.Parse("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
Guid address1_id = theAccount.Attributes.ContainsKey("address1_addressid") ? (Guid)theAccount.Attributes["address1_addressid"] : Guid.Empty;
Entity theAddress = new Entity()
{
LogicalName = "customeraddress",
Id = address1_id
};
theAddress.Attributes["line1"] = null;
theAddress.Attributes["line2"] = null;
theAddress.Attributes["line3"] = null;
theAddress.Attributes["city"] = null;
theAddress.Attributes["stateorprovince"] = null;
theAddress.Attributes["country"] = null;
theAddress.Attributes["county"] = null;
theAddress.Attributes["postofficebox"] = null;
theAddress.Attributes["postalcode"] = null;
theAddress.Attributes["composite"] = null;
proxy.Update(theAddress);
theAddress.Attributes["line1"] = "1 New Street";
theAddress.Attributes["line2"] = null;
theAddress.Attributes["line3"] = null;
theAddress.Attributes["city"] = "New City";
theAddress.Attributes["stateorprovince"] = "New State";
theAddress.Attributes["country"] = "New Country";
theAddress.Attributes["county"] = null;
theAddress.Attributes["postofficebox"] = null;
theAddress.Attributes["postalcode"] = "1234";
proxy.Update(theAddress);
Question
How do I successfully change the address composite field in Microsoft Dynamic CRM upon updating the address fields

You should update the address fields of the Account record, not the CustomerAddress.
i.e.
Entity theAccount = new Entity("account", "XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXX");
theAccount["address1_line1"] = null;
theAccount["address1_line2"] = null;
theAccount["address1_line3"] = null;
theAccount["address1_city"] = null;
theAccount["address1_stateorprovince"] = null;
theAccount["address1_country"] = null;
theAccount["address1_county"] = null;
theAccount["address1_postofficebox"] = null;
theAccount["address1_postalcode"] = null;
theAccount["address1_composite"] = null;
proxy.Update(theAccount);
theAccount["address1_line1"] = "1 New Street";
theAccount["address1_line2"] = null;
theAccount["address1_line3"] = null;
theAccount["address1_city"] = "New City";
theAccount["address1_stateorprovince"] = "New State";
theAccount["address1_country"] = "New Country";
theAccount["address1_county"] = null;
theAccount["address1_postofficebox"] = null;
theAccount["address1_postalcode"] = "1234";
proxy.Update(theAccount);
If this you're doing is a real-time operation of some kind taking place while the form is open, you also might need to invoke Xrm.Page.data.refresh(false) for the new data to show up.

Related

I need to Add a new Build(Working Fine) and update(doesn't update) an Old build at the same time

//Exception: The instance of entity type 'Citbuild' cannot be tracked because another instance //with the same key value for {'Id'} is already being tracked. When attaching existing entities, //ensure that only one entity instance with a given key value is attached. Consider using //'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values."}
foreach (var buildData in builds)
{
//make old build to Archive
buildData.BuildStatus = (long)BuildStatus.Archive;
NewBuildDto newBuild = new NewBuildDto();
newBuild = GetCopyNewBuildRecord(buildData);
newBuild.BuildStatus = (long)BuildStatus.Requested;
newBuild.DeliveryStatus = null;
newBuild.RequestDate = DateTime.Now;
newBuild.DeliveredDate = null;
newBuild.ReworkId = reworkId;
newBuild.CreatedDate = newBuild.ModifiedDate = DateTime.Now;
newBuild.CreatedBy = newBuild.ModifiedBy = currentUser;
newBuild.BuildId = newBuildId;
newBuild.LinkFile = null;
newBuild.Cpsfile = null;
newBuild.Csvlink = newBuildId;
newBuild.FileName = null;
newBuild.FtpserverId = null;
var newCitBuild = newBuild.ToDataEntity();
_context.Citbuilds.Add(newCitBuild);
_context.SaveChanges();

Elasticsearch skip null values

there are empty fields in the document I created.
var settings = new ConnectionSettings(new Uri(uri)).DefaultIndex("person");
var client = new ElasticClient(settings);
for example;
var newPerson = new Person()
{
newPerson.Name = "Jack",
newPerson.Age = 30,
newPerson.Image = "";
}
var savePerson = client.Create(newPerson , i => i.Index("person"));
I don't want to save the "Image" field when saving.
Can I ignore this field or skip it while saving?
Set the property:
newPerson.Image = null;
and it won't be saved to elastisearch

Stripe exception thrown when creating new connect account with bank account

After upgrading to the latest version of Stripe.Net.
I'm trying to create a new custom connect account, which includes a bank account, with the .Net API and Stripe is throwing this exception.
This account can only be updated with an account token, because it was originally created with an account token. (Attempted to update param 'account_token' directly.)
I'm assigning the AccountToken I'm generating from Stripe.js and that seems to be generating ok. Additionally I have no issue adding an external bank to a already created connect account. I just can't seem to create a new custom account
Here is my c# code
AccountDobOptions dobOptions = new AccountDobOptions()
{
Day = yogaProfile.Birthdate.Day,
Month = yogaProfile.Birthdate.Month,
Year = yogaProfile.Birthdate.Year
};
AddressOptions addressOptions = new AddressOptions()
{
City = bankDetails.City,
Country = bankDetails.CountryCode,
State = bankDetails.CountryCode == "US" ? bankDetails.USStateCode : bankDetails.NonUSStateCode,
PostalCode = bankDetails.PostalCode,
Line1 = bankDetails.AddressLine1,
Line2 = bankDetails.AddressLine2
};
AccountLegalEntityOptions legal = new AccountLegalEntityOptions();
legal.Dob = dobOptions;
legal.Type = "individual";
legal.Address = addressOptions;
legal.FirstName = accountFullName.Split(' ')[0];
legal.LastName = accountFullName.Split(' ')[1];
//legal.SSNLast4 = bankDetails.LastFourSSN;
AccountTosAcceptanceOptions tosOptions = new AccountTosAcceptanceOptions()
{
Date = DateTime.UtcNow,
Ip = clientIpAddress != null ? clientIpAddress : GetUserIpAddress()
};
var accountOptions = new AccountCreateOptions()
{
Email = yogaProfile.ApplicationUser.Email,
Type = AccountType.Custom,
Country = bankDetails.CountryCode,
LegalEntity = legal,
TosAcceptance = tosOptions,
AccountToken = stripeToken,
//TransferScheduleInterval = "weekly",
ExternalBankAccount = new AccountBankAccountOptions()
};
var accountService = new AccountService();
Account account = accountService.Create(accountOptions);

How to add brand to existing eBay item?

In my application I would like add Brand and MPN to existing eBay item via API on C#, so, I run code:
string eCommerceID = (dr["eCommerceID"] ?? "").ToString().Trim();
string upc = (dr["UPC"] ?? "").ToString().Trim();
string manufacturerName = (dr["ManufacturerName"] ?? "").ToString().Trim();
string brandMPN = (dr["BrandMPN"] ?? "").ToString().Trim();
ReviseItemRequestType reviseItemRequestType = new ReviseItemRequestType();
reviseItemRequestType.Version = version;
reviseItemRequestType.Item = new ItemType();
reviseItemRequestType.Item.ItemID = eCommerceID;
reviseItemRequestType.Item.ProductListingDetails = new ProductListingDetailsType();
reviseItemRequestType.Item.ProductListingDetails.UPC = upc;
reviseItemRequestType.Item.ProductListingDetails.BrandMPN = new BrandMPNType();
reviseItemRequestType.Item.ProductListingDetails.BrandMPN.Brand = manufacturerName;
reviseItemRequestType.Item.ProductListingDetails.BrandMPN.MPN = brandMPN;
ReviseItemResponseType reviseItemResponseType = ebayService.ReviseItem(reviseItemRequestType);
but when I execute this code, eBay returns error:
"The item specific Brand is missing. Add Brand to this listing, enter a valid value, and then try again."
What I'm doing wrong?
Appreciate any help. Thanks.
Error:
As the error messages says:
The item specific Brand is missing
Don't use the Item.ProductListingDetails.BrandMPN in your request. Instead you will need to create two Item Specifics called Band and MPN.
<ItemSpecifics>
<NameValueList>
<Name>Brand</Name>
<Value>[BRAND VALUE]</Value>
</NameValueList>
<NameValueList>
<Name>MPN</Name>
<Value>[MPN VALUE]</Value>
</NameValueList>
</ItemSpecifics>
Here is copy paste code snippet of the C# solution.
ItemType itemType = new ItemType(); // = class eBay.Service.Core.Soap.ItemType
Int32 condCodeAsInt = 1000; // upto you to derrive this from your use case.
String myBrandValue = "Some BRAND";
String myMpnValue = "some MPN";
String myUpcValue = "Does not apply";
....
//if condition is "New" or "New with Details" then we need to set extra REQUIRED fields
if (condCodeAsInt == 1000 || condCodeAsInt == 1500)
{
//if it is "new" then remove inputted desc text completely REQUIRED
if (condCodeAsInt == 1000)
{
itemType.ConditionDescription = "";
}
// set UPC value HERE, not in ItemSpecifics.
ProductListingDetailsType pldt = new ProductListingDetailsType();
pldt.UPC = myUpcValue;
itemType.ProductListingDetails = pldt;
//init Item specifics ( and set BRAND and MPN )
itemType.ItemSpecifics = new NameValueListTypeCollection();
//brand
NameValueListType nvBrand = new NameValueListType();
nvBrand.Name = "Brand";
StringCollection brandStringCol = new StringCollection();
brandStringCol.Add(myBrandValue);
nvBrand.Value = brandStringCol;
itemType.ItemSpecifics.Add(nvBrand);
//MPN
NameValueListType nvMpn = new NameValueListType();
nvMpn.Name = "MPN";
StringCollection mpnStringCol = new StringCollection();
mpnStringCol.Add(myMpnValue);
nvMpn.Value = mpnStringCol;
itemType.ItemSpecifics.Add(nvMpn);
}

How do I use AWS SDK for .Net to create an image to an instance I have? (AMI)

I have an Amazon EC2 instance and I need to be able to create an AMI (image) from it programmatically. I'm trying the following:
CreateImageRequest rq = new CreateImageRequest();
rq.InstanceId = myInstanceID;
rq.Name = instance.KeyName;
rq.Description = "stam";
rq.NoReboot = true;
IAmazonEC2 ec2;
AmazonEC2Config ec2conf = new AmazonEC2Config();
ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2conf);
// CreateImageResponse imageResp;
Amazon.EC2.Model.CreateImageResponse imageResp = null;
try
{
imageResp = ec2.CreateImage(rq);
}
catch (AmazonServiceException ase)
{
MessageBox.Show(ase.Message);
}
The result is always an AmazonServiceException saying that there is a NameResolutionFailure.
How do I overcome this? I tried different possible "name" possibilities but cannot find the right one.
string amiID = ConfigurationManager.AppSettings[AmazonConstants.AwsImageId];
string keyPairName = ConfigurationManager.AppSettings[AmazonConstants.AwsKeyPair];
List<string> groups = new List<string>() { ConfigurationManager.AppSettings[AmazonConstants.AwsSecurityGroupId] };
var launchRequest = new RunInstancesRequest()
{
ImageId = amiID,
InstanceType = ConfigurationManager.AppSettings[AmazonConstants.AwsInstanceType],
MinCount = 1,
MaxCount = 1,
KeyName = keyPairName,
SecurityGroupIds = groups,
SubnetId = ConfigurationManager.AppSettings[AmazonConstants.AwsSubnetId]
};
RunInstancesResponse runInstancesResponse = amazonEc2client.RunInstances(launchRequest);
RunInstancesResult runInstancesResult = runInstancesResponse.RunInstancesResult;
Reservation reservation = runInstancesResult.Reservation;
Problem eventually solved!
it turned out thyat some codelines were doing things which were already done already and removing this part:
IAmazonEC2 ec2;
AmazonEC2Config ec2conf = new AmazonEC2Config();
ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2conf);
// CreateImageResponse imageResp;
Amazon.EC2.Model.CreateImageResponse imageResp = null;
Made things clearer and no wrong repetitions happened! Now it works!

Categories