Functions are not working with Name/values input inside script step for custom Flow Action

Nilesh Wahule
Tera Guru

Hi All,

Hope everyone is enjoying working in ServiceNow 😊.

 

I am developing a custom flow action which will react based on Name/ Values inputs datatype. as shown below

 

NileshWahule1_0-1676974370406.png

which will eventually return a Object with same data inside script step. 

 

NileshWahule1_1-1676974496656.png

I have verified this object inside the logs and sending data as expected :

{"Name":"Nilesh","Dept":"SNOW"} 

 

But when I am trying to use any function inside the script step for keys and values operations as follows, its giving unexpected result :

 

NileshWahule1_2-1676974746228.png

 

The output of this script should be like -

Name=Nilesh Dept=SNOW 

but when action test is taken it shows different things as follow

 

replaceAll= function (from, to)

{

return this.replace(from.toString(), to, "g");

}

 

NileshWahule1_3-1676974966236.png

 

 

Also, when I am performing same operation through background script, I can see expected results.

 

I am new to developing the custom flow actions, but I still wonder how this is happening 😐.

 

 

Please let me know if I am doing anything wrong in syntax or some methods. 

 

Thanks in Advance.

 

 

#serviceNow #flow

1 ACCEPTED SOLUTION

Nilesh Wahule
Tera Guru

Hi All,

Thank you for your time and efforts, as we couldn't find anything related towards the solution of this issue. we did raise HI ticket and the issue is solved. 

Following were the discussion points,

1. When we use flow data pill to populate user field data population, the text will be in its original form without escaping i.e. if user has entered any special characters inside field, that will be as it is, and may cause problems while you perform next operations. 

e.g. User has entered data in address field which is multiline in the following format 

At post A'bad

Dist Aurangabad , MH''- IN

 

as this data is multiline and having special characters we should first escape it so that the special characters from the sequence will be treated as simple string characters.

Know more about the escape Sequence 

 

2. There is OOB JavaScript utility provided by ServiceNow to esacpe and unescape the string text called as JSUtil. this script include helps preventing the breaking into the strings cause of specials symbols, you can use it as follow 

JSUtil.escapeText(String) and then serialize and JSUtil.unescapeText(String) and then de-serialize. 

Util URI: https://<<YOUR INSTANCE ADDRESS>>.service-now.com/sys_script_include.do?sys_id=8d5571660a0a0b5000fc9...

Note : Please take full API name if you are working for scoped Applications.

 

3. For better user performance and better efficiency, we should restrict fields on client side itself, use an onChange or onSubmit Client Script to capture the special characters

 e.g. refer to this Community post

 

 

At the end coming to main problem, How I am able to pass correct string inside the flow action input is, I have created a flow variables for all these fields which may contain a special characters and then using JSUtil serialized it. At the end instead of passing simple data from field , I passed the flow variable with escaped text.

 

Hope this will help for you all.

 

 

View solution in original post

9 REPLIES 9

Nilesh Wahule
Tera Guru

Hi @Ankur Bawiskar @Community Alums  @John Zhang1 ,

Please help !!

Ankur Bawiskar
Tera Patron
Tera Patron

@Nilesh Wahule 

did you try creating output variable of type object or json?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello @Ankur Bawiskar ,

I did not try that as my goal is filling these fields data dynamically in html description which is string, so I want string output.

Thank you !!

@Nilesh Wahule 

can you please share what's your business requirement along with screenshots?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader