Not able to get Request sys_id and number using CartJS API in Kingston

Jonas Lundsholm
Mega Contributor

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.

1 ACCEPTED SOLUTION

Upgrade to Kingston patch 9 solved the issue.

View solution in original post

9 REPLIES 9

Jonas Lundsholm
Mega Contributor

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.

 

Jonas Lundsholm
Mega Contributor

I just found another post where they are saying that this is an issue in Kingston and should be fixed in patch 7. Running an upgrade of my dev instance now. I'll update when I have more information.

https://community.servicenow.com/community?id=community_question&sys_id=47d4cfe9dbd8dbc01dcaf3231f96...

Upgrade to Kingston patch 9 solved the issue.

Hi Jonas,

Can you also mark the answer as correct and helpful if this is solved. Thanks in advance.

Regards

Ankur

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

nirwan_ritik
Tera Contributor

I have the same issue. We are in UTAH. Facing same issue. How to get the sys_id of the request?