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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

"Input string was not in a correct format" custom action error

(0) ShareShare
ReportReport
Posted on by 2,510

Hi, I keep getting this error message when invoking the action from javascript, please advise, I attached the c# code.

2017_2D00_11_2D00_16_5F00_1633.png

2017_2D00_11_2D00_16_5F00_16333.png

 [Input("Application Reference")]
        [ReferenceTarget("recoserv_application")]
        [Default("8B446743-C6C4-E711-A81C-005056B5FEFA", "recoserv_application")]
        public InArgument<EntityReference> ApplicationRef { get; set; }

        [Input("Amount")]
        public InArgument<string> Amount { get; set; }
       
        [Input("AuthCode")]
        public InArgument<string> Authcode { get; set; }

        [Output("PaymentID")]
        [AttributeTarget("recoserv_payment)", "recoserv_paymentid")]
        public OutArgument<string> PaymentId { get; set; }
        
        public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
        {
            //Create the tracing service
            ITracingService tracingService = executionContext.GetExtension<ITracingService>();
            //Create the context
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            tracingService.Trace("applicationref: {0}", ApplicationRef.ToString());
            tracingService.Trace("amount: {0}", Amount);
            tracingService.Trace("authcode: {0}", Authcode);



            if (crmWorkflowContext == null)
            {
                throw new ArgumentNullException("crmWorkflowContext is null");
            }

	        try
	        {
                using (CrmServiceContext csc = new CrmServiceContext(service))
                {
                    var item = (from c in csc.recoserv_paymentSet
                                where c.recoserv_application.Id == this.ApplicationRef.Get(executionContext).Id
                                orderby c.CreatedOn descending
                                select c).FirstOrDefault();
                    //Entity payment = service.Retrieve("recoserv_payment", item.Id, new ColumnSet(true));
                    if (item!=null && item.StatusCode.Value ==1 && item.recoserv_actualamount.Value == decimal.Parse(Amount.ToString()))
                        {
                        tracingService.Trace("statuscode: {0}", item.StatusCode.Value.ToString());
                        tracingService.Trace("Payment ID: {0}", this.ApplicationRef.Get(executionContext).Id.ToString());
                        //update payment status
                        SetStateRequest request = new SetStateRequest();
                        request.EntityMoniker = new EntityReference(recoserv_payment.EntityLogicalName, item.Id);
                        request.State = new OptionSetValue((int)recoserv_paymentState.Active);
                        request.Status = new OptionSetValue((int)recoserv_payment_StatusCode.Paid); // Paid
                        SetStateResponse response = (SetStateResponse)service.Execute(request);
                        //update payment authcode
                        item.recoserv_authcode = Authcode.ToString();
                        //payment["recoserv_authcode"] = Authcode;
                        service.Update(item);
                        this.PaymentId.Set(executionContext, item.recoserv_paymentId);
                    }
                }
            }
            catch (FaultException<OrganizationServiceFault> e)
            {
                tracingService.Trace("Exception: {0}", e.ToString());
                tracingService.Trace("Timestamp: {0}", e.Detail.Timestamp);
                tracingService.Trace("Code: {0}", e.Detail.ErrorCode);
                tracingService.Trace("Message: {0}", e.Detail.Message);
                tracingService.Trace("Trace: {0}", e.Detail.TraceText);
                throw e;
            }


*This post is locked for comments

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at
    RE: "Input string was not in a correct format" custom action error

    Hi,

     not sure where it's failing - do you have traces from the trace log?

     that item.recoserv_paymentId- is it an entity reference? You seem to be trying to put it into a string output..

  • Mahendar Pal Profile Picture
    45,095 on at
    RE: "Input string was not in a correct format" custom action error

    You can try to change that line to

    this.PaymentId.Set(executionContext, item.recoserv_paymentId.Id.ToString());

    thanks

  • sdnd2000 Profile Picture
    2,510 on at
    RE: "Input string was not in a correct format" custom action error

    Yes, I did change that line, but still got the same error, here is the trace log, it looks like the it doesn't get the input string?

    6215.2017_2D00_11_2D00_16_5F00_1633.png

  • Verified answer
    ashlega Profile Picture
    34,477 on at
    RE: "Input string was not in a correct format" custom action error

    Try adding return to the first line.. I am wondering if it's an error in that code or in how you are passing the parameters. One other place where it looks suspicious is where you are calling tracing service with the input parameters without using get..

  • sdnd2000 Profile Picture
    2,510 on at
    RE: "Input string was not in a correct format" custom action error

    Thanks Alex, it was caused by without using get. But I got new error as the below, I guess it is caused by the update method.

    2475.2017_2D00_11_2D00_16_5F00_1633.png

      using (CrmServiceContext csc = new CrmServiceContext(service))
                    {
                        var item = (from c in csc.recoserv_paymentSet
                                    where c.recoserv_application.Id == this.ApplicationRef.Get(executionContext).Id
                                    orderby c.CreatedOn descending
                                    select c).FirstOrDefault();
                        //Entity payment = service.Retrieve("recoserv_payment", item.Id, new ColumnSet(true));
                        tracingService.Trace("applicationref: {0}", ApplicationRef.ToString());
                        tracingService.Trace("amount: {0}", Amount);
                        tracingService.Trace("authcode: {0}", Authcode);
                        if (item!=null && item.StatusCode.Value ==1 && item.recoserv_actualamount.Value == decimal.Parse(Amount.Get<string>(executionContext)))
                            {
                            tracingService.Trace("statuscode: {0}", item.StatusCode.Value.ToString());
                            tracingService.Trace("Payment ID: {0}", this.ApplicationRef.Get(executionContext).Id.ToString());
                            //update payment status
                            SetStateRequest request = new SetStateRequest();
                            request.EntityMoniker = new EntityReference(recoserv_payment.EntityLogicalName, item.Id);
                            request.State = new OptionSetValue((int)recoserv_paymentState.Active);
                            request.Status = new OptionSetValue((int)recoserv_payment_StatusCode.Paid); // Paid
                            SetStateResponse response = (SetStateResponse)service.Execute(request);
                            //update payment authcode
                            item.recoserv_authcode = Authcode.Get<string>(executionContext);
                            //payment["recoserv_authcode"] = Authcode;
                            service.Update(item);
                            this.PaymentId.Set(executionContext, item.recoserv_paymentId.ToString());
                        }


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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans