web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

invalid argument error in plugin

(0) ShareShare
ReportReport
Posted on by 185

hi,

I have 3 entity,but i have to automate 4 fields in 1 entity through plugin,but after execution its showing the below error:

this is my C# code:

if (context.Depth <= 1)
{

if (EntitySample != null)
{
Origin = EntitySample.FormattedValues["cim_origin"].ToString();
Destination = EntitySample.FormattedValues["cim_destination"];
ProductType = EntitySample1.FormattedValues["cim_producttype"].ToString();

ExpresionSC.ColumnSet = new ColumnSet(true);
EntityCollection colection = service.RetrieveMultiple(ExpresionSC);
ExpresionTC.ColumnSet = new ColumnSet(true);
EntityCollection colection1 = service.RetrieveMultiple(ExpresionTC);
if (colection != null && colection1 !=null)
{
//try
// {
foreach (Entity En in colection.Entities)
{
string OriginSC = En.FormattedValues["cim_origin"];
string DestinationSC = En.FormattedValues["cim_destinations"];

foreach (Entity En1 in colection1.Entities)
{
string ProductTypeTC = En1.FormattedValues["cim_typesofproducts"].ToString();

if (Origin == OriginSC && Destination == DestinationSC && ProductType == ProductTypeTC)
{

string duration = En.GetAttributeValue<string>("cim_transportdurations");
EntitySample["cim_shipmentduration"] = duration;

decimal cost = En.GetAttributeValue<Money>("cim_shipmentcost").Value;
EntitySample["cim_shipmentcost"] = new Money(cost);

DateTime date = EntitySample.GetAttributeValue<DateTime>("cim_startdate");
DateTime dt = date.AddDays(Convert.ToDouble(duration));
EntitySample["cim_estimatearrivaltime"] = dt;

Duration = En1.GetAttributeValue<string>("cim_duration");
EntitySample1["cim_testingdurtion"] =int.Parse(Duration);
service.Update(EntitySample);
service.Update(EntitySample1);

}
}

and the eror is:Invalid Argument

and  the downloaded errordetails is:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Incorrect type of attribute value System.Int32Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220989</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>Incorrect type of attribute value System.Int32</Message>
<Timestamp>2014-07-22T04:40:20.8594715Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText>

[Automation4ShipmentcostReq: Automation4ShipmentcostReq.Class1]
[18e3fa35-0211-e411-aa35-d89d67644f08: Automation4ShipmentcostReq.Class1: Update of cim_labbooking]


</TraceText>
</OrganizationServiceFault>

plz solve it  as soon as possible, its very very urgent,plz solve it quickly

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Sathiamoorthy S Profile Picture
    1,616 on at

    Hi,

    On seeing the error message,

    <Message>Incorrect type of attribute value System.Int32</Message>

    It looks there’s a problem in assigning or setting value to the Integer/whole number field in below code.

    Duration = En1.GetAttributeValue<string>("cim_duration");
    EntitySample1["cim_testingdurtion"] =int.Parse(Duration);

    Thanks!

  • Suggested answer
    Andre Margono Profile Picture
    2,602 on at

    Incorrect type of attribute value System.Int32 -> this error message usually comes from the incorrect data type that set into the attribute.

    I suspect it's coming from this line: EntitySample1["cim_testingdurtion"] =int.Parse(Duration);

    Check whether the data type of field "cim_testingdurtion" is whole number (int) or not.

  • Suggested answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi Sasmita,

    In your first code:

    string duration = En.GetAttributeValue<string>("cim_transportdurations");

    EntitySample["cim_shipmentduration"] = duration;

    --> It means that you assigned EntitySample["cim_shipmentduration"]  field to string

    --> cim_shipmentduration attribute, what is the data type? string or int? If int, then don't forget to convert to int

    EntitySample["cim_shipmentduration"] = Convert.ToInt32(duration);

    Duration = En1.GetAttributeValue<string>("cim_duration");

    EntitySample1["cim_testingdurtion"] =int.Parse(Duration);

    --> It means that you assigned to int32

    There are two different fields, but both of them are duration, do you set to this field int or string?

    Thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans