How to remove the '\n' from the output of Powershell on Workflow's activity designer?

Bird1
Mega Sage

Hello,

 

I need 1 help. I do have Powershell Script to create Active Directory account, so I create 'activity designer' and embed the Powershell script there. The output is set as 'Direct'. 

 

So far, the Powershell Script works well, it could create Active Directory account but I faced the Output in that activity designer, it will always add '\n' as prefix so like below captured screen, the script could create Active Directory account: 'mit' but the Output will show as '\nmit'. 

 

I will really need this output to be the input of the next activity, so it will be failed because of '\n' prefix.

 

I am not sure is there any way to

A) remove the '\n' either from the output 

B) if the choice A) to remove '\n' from the output of current activity is not possible, can we remove '\n' from the input of the next activity designer instead?

 

PS: I have tried the same Powershell Script adding to action designer on the Flow Designer, there's no problem, it could return output as 'mit' without '\n' prefix, so the problem is only from Activity Designer's workflow

 

 

 

Bird1_1-1701830508437.png

 

 

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @Bird1 

Coming to the option B,

You can have a Script Activity and use the replace method on the output string. Like YourVariable.replace("\\n", ""); and store it into a scratch pad variable for use in other work flow activities.

 

If the above one didn't work, try just \n instead of \\n.

 

Please mark my answer helpful and accept as a solution if it helped 👍

Thanks,
Anvesh

View solution in original post

11 REPLIES 11

Vishal Birajdar
Giga Sage

Hello @Bird1 

 

Can you try using trim() like below :

 

activityOutput.Output = activityOutput.Output.trim();

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

I've tried below script but still getting '\n' prefix, so weird.

 

activityOutput.Output = activityOutput.Output.trim();