Personalized Community is here!
Quickly customize your community to find the content you seek.
Have questions on moving to the cloud? Visit the Dynamics 365 Migration Community today! Microsoft’s extensive network of Dynamics AX and Dynamics CRM experts can help.
2021 Release Wave 2Discover the latest updates and new features releasing from October 2021 through March 2022.
2021 release wave 2 plan
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Community | FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Upcoming TechTalks | All TechTalks
I'm writing a console app to upload file .csv into CRM. Here is my code:
var hundredData = File.ReadAllLines(@"..\..\Data\ImportList100Data.csv");
var dataList = from detailData in hundredData
let data = detailData.Split(';')
GroupName = data,
ProjectNumber = data,
Name = data,
Members = data,
Customer = data,
ProjectStatus = data,
StartDate = data,
EndDate = data
var list = dataList.ToList();
int totalData = list.Count();
int successUpd = 0;
int successCreate = 0;
log.Info("There are " + (totalData - 1) + " items to be processed");
var systemUser = getSystemUser(crmSvc);
for (int i = 1; i < list.Count(); i++)
var data = list[i];
DateTime startDate = DateTime.Parse(data.StartDate);
DateTime endDate = DateTime.Parse(data.EndDate);
optSet = 283630000;
optSet = 283630001;
case "In Progress":
optSet = 283630002;
optSet = 283630003;
throw new Exception("Invalid choice");
var visa = addMem(crmSvc, data.Members);
var proj = getProjID(context, data.ProjectNumber.ToString());
elca_Project newProject = new elca_Project();
newProject.new_ProjectGroup = QueryGroup(context, data.GroupName);
newProject.elca_name = data.Name.ToString();
newProject.elca_Customer = data.Customer.ToString();
newProject.elca_StartDate = startDate;
newProject.elca_EndDate = endDate;
newProject.elca_ProjectStatus = new OptionSetValue(optSet);
newProject.elca_Members = visa;
newProject.OwnerId = systemUser;
if (proj != null)
newProject.Id = proj.Id;
log.Info("Item " + i + "/" + (totalData - 1) + ": Project was updated");
newProject.elca_ProjectNumber = data.ProjectNumber.ToString();
log.Info("Item " + i + "/" + (totalData - 1) + ": Project was created");
log.Error("Item " + i + "/" + (totalData - 1) + ": Failed with error " + e.Message, e);
And get systemuser:
static EntityReference getSystemUser(CrmServiceClient crmSvc)
WhoAmIRequest systemUserRequest = new WhoAmIRequest();
WhoAmIResponse systemUserResponse = (WhoAmIResponse)crmSvc.Execute(systemUserRequest);
Guid userId = systemUserResponse.UserId;
return new EntityReference("systemuser", userId);
But I get the error like this even I don't call any account. How to fix it?
Thanks a lot.
Have you checked if there is a plugin running on the entity you're trying to update? Try disabling it
Thank you but I still get that problems after disabling all my plugins, can I try some thing else?
One thing to look at is it seems that you have a "Customer" data type in your entity. The Customer data type can reference a Contact or an Account. If there's something else in this process/code that assumes a Contact or an Account, that could be the issue. For example it might be looking to find an account by id in the customer field, but the GUID is really for a Contact.
Actually the Customer is just a text field, but the Owner is an entity reference and I have post the code to retrieve the ownerid, can you please check it if I have any mistakes? Because I try finding which related to Account but there is not
The systemuser part looks right to me. What does your addMem() method do? If you've stepped through the code with breakpoints, what line is throwing the exception? Are any rows getting added to the elca_Project entity, or are all input lines from the csv failing?
One more thing. What data type is your elca_Members field on the elca_Project entity?
It's just to get a string, I've put breakpoint but no rows throw exception, when I try to show the csv in console it's all ok but the error still exist
Yah it's string and I've already get it.
Thanks for all of your answer.
I've found out the problem that there is a unexpected relationship between the project and account, so I just delete and it works well
I'm glad you found and fixed the problem. Tracking things down like that can be tricky.
Business Applications communities