- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2016 05:10 PM
Hi,
Once again im bitten by DataTime issues. Can I include a third party jacascript lib in service now and then use it in Transform Map. If yes please share the procedure.
For example if i want to include Moment Timezone in service now is it possible?
P.S. the format i am trying to parse is 07/16/15 16:22:05 which gives me exception. Target format in which i want it to be is 2016-07-07 20:04:27
This is the code that i tried
var sourceTime = '07-16-15 16:22:05';
var gd = new GlideDateTime(sourceTime);
gd.setValueUTC(sourceTime, "MM-dd-yyyy HH:mm:ss");
var test = gd.getValue();
gs.print(test);
Exception:
Evaluator: java.lang.RuntimeException: '07/16/15 16:22:05' could not be parsed using format string 'yyyy-MM-dd HH:mm:ss' :Unparseable date: "07/16/15 16:22:05" Caused by error in script at line 3 1: var sourceTime = '07/16/15 16:22:05'; 2: var gd = new GlideDateTime(sourceTime); ==> 3: gd.setValueUTC(sourceTime, "yyyy-MM-dd HH:mm:ss"); 4: var test = gd.getValue(); 5: gs.print(test); 6: com.glide.glideobject.GlideDateTime.setValueUTC(GlideDateTime.java:255) sun.reflect.GeneratedMethodAccessor1949.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138) org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:292) org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2577) org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:42) org.mozilla.javascript.gen.null_null_10905._c_script_0(null.null:3) org.mozilla.javascript.gen.null_null_10905.call(null.null) org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:560) org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3439) org.mozilla.javascript.gen.null_null_10905.call(null.null) org.mozilla.javascript.gen.null_null_10905.exec(null.null) com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:236) com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:107) com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:73) com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:322) com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:283) com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:254) com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:242) com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:320) com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:215) com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:173) com.glide.processors.AProcessor.runProcessor(AProcessor.java:412) com.glide.processors.AProcessor.processTransaction(AProcessor.java:187) com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:165) com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:49) com.glide.sys.ServletTransaction.run(ServletTransaction.java:34) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:745)
If i am doing it wrong please suggest.
Regards,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2016 01:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2016 05:14 PM
Your sourceTime only has two digits in the year. Your format is calling for 4.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2016 05:15 PM
Try this.
var sourceTime = '07-16-2015 16:22:05';
var gd = new GlideDateTime(sourceTime);
gd.setValueUTC(sourceTime, "MM-dd-yyyy HH:mm:ss");
var test = gd.getValue();
gs.print(test);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2016 05:24 PM
Hi thanks for your time. It must be a typo, im trying alot of things
var sourceTime = '07/16/15 16:22:05'; //value i am getting in excel
var gd = new GlideDateTime(sourceTime);
gd.setValueUTC(sourceTime, "MM-dd-yyyy HH:mm:ss");//this is the target format
var test = gd.getValue();
gs.print(test);
i cannot change the source format( using regex will be too messy? as i will be getting alot of excel files?)
i was thinking if i can include a 3rd party js lib which can handle multiple formats would be easier. Your thoughts, comments are valuable
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2016 05:26 PM
please notice the / in source datetime instead of -