Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to replace text in script include

Milan13
Giga Expert

Hello,

I have catalog client script and script include to which I pass value of date_from field from form and I retrieve this in Script include, however I need to replace the dots in the output with slashes but it just does not work.

Anything I have been doing wrong?

Please see below...

Many thanks,

Milan

 

 

Client script code snippet from GlideAjax:

ga.addParam('sysparm_date_from', g_form.getValue('date_from'));

 

Script Include side:
1.) var date_from = this.getParameter('sysparm_date_from');  - when I view the output it gives me a date in this form: 30.10.2019 11:03:07

2.) var date_from = this.getParameter('sysparm_date_from').replace(/\//g, '.'); - the required output is 30/10/2019 11:03:07  however this gives me 'null' instead when being viewed...

 

6 REPLIES 6

SatheeshKumar
Kilo Sage

can you try this!

 

var date_from = this.getParameter('sysparm_date_from'); 

 

date_from = date_from.toString().replace(/\//g, '.');

 

-Satheesh

 

Omkar Mone
Mega Sage

Hi 

Try with this - 

var date_from = this.getParameter('sysparm_date_from');

var convertedDate = date_from.toString().replace(/\//g, '.');

gs.print(convertedDate);

 

Try this.

 

Regards

Omkar Mone

Anurag Tripathi
Mega Patron
Mega Patron

Try this

 

this.getParameter('sysparm_date_from').toString().replace(/\//g, '.');

-Anurag

Ahmmed Ali
Giga Sage
Giga Sage

var t = "30.10.2019 11:03:07";
gs.print(t);
var s = t.replace(/\./g,"/");
gs.print(s);

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali