- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2018 11:58 PM
I'm trying to use the CartJS API in order to create a new Request. I found this example in CartJS orderNow documentation and it's supposed to return information about the created Request's sys_id and number.
var cart = new sn_sc.CartJS();
var request =
{
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
'sysparm_quantity': '1',
'variables':{
'carrier': 'at_and_t_mobility',
'data_plan': '500MB',
'duration': 'eighteen_months',
'color': 'slate',
'storage': 'sixtyfour'
}
}
var cartDetails = cart.orderNow(request);
gs.info(cartDetails);
Running this as a background script in a scope on a dev instance gives me the following result:
completed Begin(b99518ba0a0a0b3434eaee2681c9bf5b): event=execute
completed Set Requested(b995881d0a0a0b342c5a5cc6a3466181): event=execute
completed Price <= $1,000?(b99edf740a0a0b347920c18cc18043a7): event=execute
completed Automatic approval(b9b3cf360a0a0b344188f2a09c6b349f): event=execute
completed Approved(b99b1ce30a0a0b344bea3afbf97dfa49): event=execute
completed End(b99519d50a0a0b3434eaee26bf2e812a): event=execute
*** Script: APPROVAL = approved CHANGES = true
*** Script: CURRENT STAGE = requested
*** Script: DESIRED = in_process
completed Begin(8c86ca9037023000158bbfc8bcbe5dc3): event=execute
completed (8486ca9037023000158bbfc8bcbe5dcc): event=execute
completed Is Procurement turned on(c086ca9037023000158bbfc8bcbe5dcd): event=execute
completed Source Item(4486ca9037023000158bbfc8bcbe5db2): event=execute
Slow business rule 'Start Workflow' on sc_req_item:RITM0010050, time was: 0:00:00.167
Slow business rule 'Cascade Request Approval to Request Item' on sc_request:REQ0010044, time was: 0:00:00.330
Evaluator: java.lang.NullPointerException
Caused by error in script at line 14
11: 'storage': 'sixtyfour'
12: }
13: }
==> 14: var cartDetails = cart.orderNow(request);
15: gs.info(cartDetails);
com.glideapp.servicecatalog.CartRecord.checkout(CartRecord.java:1162)
com.glideapp.servicecatalog.CartRecord.checkoutCart(CartRecord.java:1148)
com.glideapp.servicecatalog.scoped.api.CartJS.jsFunction_orderNow(CartJS.java:529)
sun.reflect.GeneratedMethodAccessor1114.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.FunctionObject.doInvoke(FunctionObject.java:670)
org.mozilla.javascript.FunctionObject.call(FunctionObject.java:614)
org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2582)
org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
org.mozilla.javascript.gen.null_null_script_1714._c_script_0(null.null.script:14)
org.mozilla.javascript.gen.null_null_script_1714.call(null.null.script)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:563)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3428)
org.mozilla.javascript.gen.null_null_script_1714.call(null.null.script)
org.mozilla.javascript.gen.null_null_script_1714.exec(null.null.script)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:263)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:110)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:76)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:309)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:214)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:201)
com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:330)
com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:219)
com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:177)
com.glide.processors.AProcessor.runProcessor(AProcessor.java:483)
com.glide.processors.AProcessor.processTransaction(AProcessor.java:205)
com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:178)
com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:167)
com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:31)
com.glide.sys.Transaction.run(Transaction.java:2038)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
It seems like a Request is created, but then there is some type of error and the sys_id and request number is never returned.
Evaluator: java.lang.NullPointerException
Caused by error in script at line 14
11: 'storage': 'sixtyfour'
12: }
13: }
==> 14: var cartDetails = cart.orderNow(request);
15: gs.info(cartDetails);
Any idea what's going on here?
I need to get access to the sys_id in order to locate the request and ritm so that I can update additional fields.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 02:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 12:03 AM
Hi Jonas,
you are trying to print cartDetails variable. Does the orderNow function return anything?
Did you check in the documentation?
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 01:08 AM
Hello Ankur,
Yes, the documentation states that this is the expected output
If the two-step checkout enabled: {"cart_id":"55384df3c322320076173b0ac3d3aec5"} If the two-step checkout disabled: {"request_id":"4c690137c322320076173b0ac3d3ae03", "request_number": "REQ0010003"}
But instead I get the error that you can see in my first post.
Two-step checkout is disabled in my dev instance, and that is the default setting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 01:27 AM
I actually get the same result using either of the functions designed to submit the cart.
checkoutCart()
orderNow(Map request)
submitOrder(Map request)
According to the documentation they should all return sys_id and request number, but all I get is the error message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 01:27 AM
I actually get the same result using either of the functions designed to submit the cart.
checkoutCart()
orderNow(Map request)
submitOrder(Map request)
According to the documentation they should all return sys_id and request number, but all I get is the error message.