NuGet Package Output String

Hi all,

I refer to the post : https://docs.uipath.com/activities/docs/creating-a-custom-activity
I am trying to create a simple activity where it inputs two strings, adds a NewLine between them and outputs a string.

My C# code for .dll is as follows:

using System.ComponentModel;
using System.Activities;
namespace Hello
{
    public class LogMessage : CodeActivity
    {
        [Category("Input")]
        [RequiredArgument]
        public InArgument<string> Message { get; set; }

        [Category("Input")]
        public InArgument<string> Add { get; set; }

        [Category("Output")]
        public OutArgument<string> Result { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            Result.Set(context, Message.Get(context) + System.Environment.NewLine + Add.Get(context));
        }
    }

I have deployed the package and used the activity but the result is as follows:
image

Does anyone know the reason and any workarounds this?

Thanks in advance.

@Gluon

Try \n instead of System.Environment.NewLine

Hi @lakshman
It is returning me the same screenshot as shown in my original post.
Thanks for your reply though

1 Like

Try this code @Gluon

  public class LogMessage : CodeActivity
   {
    [Category("Input")]
    [RequiredArgument]
    public InArgument<string> Message { get; set; }

    [Category("Input")]
    public InArgument<string> Add { get; set; }

    [Category("Output")]
    public OutArgument<string> Result { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
        var message = Message.Get(context);
        var add = Add.Get(context);
        var dummy = message + System.Environment.NewLine + add;
        Result.Set(context,dummy);
    }
}
2 Likes

Yes,

it is working for me @Gluon

image

Thanks, its working for me as well.
For understanding purposes, would you be able to explain why my previous code did not work?

context is a inherited class parameter we need to pass. So, instead of setting the value directly while setting, we need to pass the final value… This was not a problem ofcourse,

I think, we need to get the value from the getters and setters, we need to get a value before using it. We can’t directly pass it. I got the same error with the getters when I tried the same in JAVA. But I don’t understand it why errors in C# @Gluon

1 Like

Thanks for the help.
Also, do you know which part of the code to add should i want to change the description of the input/output?

Add and Message are the two string type inputs you need to provide @Gluon

I don’t understand your question. Can you please elaborate :slight_smile:

Apologies, I wanted to edit the description in the red box.
I can do that by [Description("")]

Thanks @HareeshMR

yes, I haven’t tried it till now :slight_smile:.
Thank you for letting me know. Learnt a new thing today.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.