Announcements
Hi All,
we have a c# application which has to create Invoice in MS CRM 2013. Below snap shot shows the attributes and their values filled for the invoice object.
i get 'Incorrect attribute value type System.String' exception on the Guid id = _orgService.Create(crmInvoice); line of code.
for setting customerid have tried multiple below options but all give same error.
1st Approach
crmInvoice.Attributes["customerid"] = accountId; crmInvoice.Attributes["customeridtype"] = 1;
on above approach failure tried 2nd below approach.
Entity customer = new Entity("customer"); customer.Id = accountId; customer.Attributes["type"] = "account"; //1; crmInvoice.Attributes["customerid"] = customer;
when this also failed tried 3rd approach.
crmInvoice.Attributes["customerid"] = new EntityReference("account", accountId);
This too gives same error. Kindly let me know where am going wrong. how to resolve this issue. It is turning out to be a night mare now
*This post is locked for comments
make sure your account is valid it is also possible that you are getting erorr from other GUID attributes ,you can put entity reference us the same method of Customer ID .
I had this same issue where I was not getting the attribute that was failing. I was using a workflow action, so I could see the error, but no info about the specific attribute that was causing the problem. I was having issues getting the trace files (no Sandbox trace), so I changed the registration of the dll to be out of the sandbox. Lo and behold, the error trace printed into the workflow dialog box included the offending field (of literally hundreds, so thank goodness). Obviously, this isn't an option for everyone, but it does help a lot if it is possible.
oh, sorry. well my idea was trying to hard-type the id.
I'd run all the attributes though a tracert just to see what kind of values they return (string, in, etc), especially when running .GetValue()
my question was: Why does it not tell me what field has the "Incorrect attribute value type"
try
Guid id = (Guid)_orgService.Create((Entity)crmInvoice);
I am getting the same error with a field of type EntityReference. but I am very annoid that it doesn't specify which field, and I have several. Should I check every field? is this my only option?
Shoab,
There are lines you need to notice and amend it.
I don't think you can just give the invoicenumber like this:
For the entity reference, do not split like that, instead using the same concept with customerid and also for the new_paidamount, please use new Money(Math.Abs(Convert.ToDecimal(qbInvoice.AppliedAmount.GetValue())));
And also crmInvoice.Attributes["new_qblistid"] =
You sure this one is not an entityreference???
crmInvoice.Attributes["statecode"] = 2;
You cannot use this one..
You can either later update it using the SetStateRequest or you need to use option set one
crmInvoice.Attributes["statecode"] = new OptionSetValue(2);
then also give its pair, the status code, make sure they are in pair one.
And this one is a date or string
crmInvoice.Attributes["new_syncupdate"] = syncDate.ToString();
Even though you fix the string one, there are other things to fix.
Thanks.
Hi Pramod,
Thanks for your reply. It is a string. Have posted full code for filling invoice object properties in one of the replies. Could please see wht could be worng in it
Hi Himbap, Thanks for your reply. I have added my full code for entity object property setting.
Hello Aileen,
Thanks for the reply. below is my code to fill invoice entity object values
Entity crmInvoice = new Entity(); crmInvoice.Attributes["name"] = qbInvoice.CustomerRef.FullName.GetValue() + "-INV-" + qbInvoice.RefNumber.GetValue(); crmInvoice.Attributes["name"] = qbInvoice.CustomerRef.FullName.GetValue(); crmInvoice.Attributes["invoicenumber"] = qbInvoice.RefNumber.GetValue(); crmInvoice.Attributes["new_invoicehash"] = qbInvoice.RefNumber.GetValue(); RetrieveMultipleResponse retrievedResponse = CommonEntityOperation.getRecordIdByName("pricelevel", "name", "Kyra-base-price-list");//getPriceListID(); EntityCollection beCollection = retrievedResponse.EntityCollection; //pricelevel priceList = (pricelevel)beCollection[0]; Entity priceList = beCollection[0]; Guid priceListID = (Guid)priceList.Attributes["pricelevelid"]; //crmInvoice.pricelevelid = new Lookup(); //crmInvoice.pricelevelid.Value = priceListID; crmInvoice.Attributes["pricelevelid"] = new EntityReference(); crmInvoice.Attributes["pricelevelid"] = priceListID; string customerListId = qbInvoice.CustomerRef.ListID.GetValue(); retrievedResponse = CommonEntityOperation.getRecordIdByName("account", "new_qblistid", customerListId);//getPriceListID(); beCollection = retrievedResponse.EntityCollection; //account customerAccount = (account)beCollection[0]; Entity customerAccount = (Entity)beCollection[0]; Guid accountId = (Guid)customerAccount.Attributes["accountid"]; crmInvoice.Attributes["customerid"] = new EntityReference("account", accountId); crmInvoice.Attributes["paymenttermscode"] = 200000 + paymentTermValue; date = qbInvoice.TxnDate.GetValue(); crmInvoice.Attributes["datedelivered"] = date.ToString(); crmInvoice.Attributes["new_qbcreatedon"] = date.ToString(); crmInvoice.Attributes["new_ponumber"] = qbInvoice.PONumber.GetValue(); date = qbInvoice.DueDate.GetValue(); //crmInvoice.duedate = new COMMON.CrmSdk.CrmDateTime(); //crmInvoice.duedate.Value = date.ToString(); crmInvoice.Attributes["duedate"] = date.ToString(); crmInvoice.Attributes["new_class"] = qbInvoice.ClassRef.FullName.GetValue(); crmInvoice.Attributes["new_paidamount"] = new Money(); crmInvoice.Attributes["new_paidamount"] = Math.Abs(Convert.ToDecimal(qbInvoice.AppliedAmount.GetValue())); crmInvoice.Attributes["statecode"] = 2; //Value of InvoiceState.Paid; crmInvoice.Attributes["new_qblistid"] = qbInvoice.TxnID.GetValue(); DateTime syncDate = System.DateTime.Now; syncDate = syncDate.AddMinutes(2); //crmInvoice.new_syncupdate = new COMMON.CrmSdk.CrmDateTime(); crmInvoice.Attributes["new_syncupdate"] = syncDate.ToString();
Note : GetValue() function returns a string.
Kindly help me identifiying where am going wrong.
André Arnaud de Cal...
294,120
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator