
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2016 01:36 PM
I am using the following script on an inbound email action. It works as expected when the email address is matched to an existing user, but for guest users it creates the REQ and RITM, but the RITM workflow doesn't start until the RITM is saved from the form. Then the workflow on the RITM kicks off and creates the first task.
var cart = new Cart();
cart.requested_for = gs.getUserID();
var item = cart.addItem('724f863d13e95640bc4830782244b002');
var details = 'Sender: ' + email.origemail + '\n\n';
details += 'To: ' + email.direct + '\n\n';
if (email.copied) {
details += 'CC: ' + email.copied + '\n\n';
}
details += 'Subject: ' + email.subject + '\n\n';
details += 'Body:\\n' + email.body_text;
cart.setVariable(item, 'v_details', details);
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
var rc = cart.placeOrder();
// Add attachments to RITM
var ritmSysID = "";
var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request", rc.sys_id);
ritmRec.query();
if(ritmRec.next()){
ritmSysID = ritmRec.sys_id;
}
var emailRec = new GlideRecord("sys_email");
emailRec.addQuery("uid", email.uid);
emailRec.orderByDesc("sys_created_on");
emailRec.query();
if(emailRec.next()){
GlideSysAttachment.copy("sys_email", emailRec.sys_id, "sc_req_item", ritmRec.sys_id);
}
I get the following errors in the log if they might help pinpoint the issue:
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line -1
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line 1
==> 1: sc_req_item_stageGetChoices()
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line 1
==> 1: sc_req_item_stageGetChoices()
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line -1
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in Business Rule: 'sc_req_item_stageGetChoices' at line 41
38: else {
39: // We have not started a workflow for the item yet (pending request
40: // approval) so determine the version we will eventually be using
==> 41: version = new Workflow().getVersion(current.cat_item.workflow).sys_id + '';
42: }
43: wfs.setWorkflowVersion(version, current.context + '');
44: wfs.getChoices(current.stage, answer);
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line 1
==> 1: sc_req_item_stageGetChoices()
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line -1
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line -1
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in Business Rule: 'sc_req_item_stageGetChoices' at line 41
38: else {
39: // We have not started a workflow for the item yet (pending request
40: // approval) so determine the version we will eventually be using
==> 41: version = new Workflow().getVersion(current.cat_item.workflow).sys_id + '';
42: }
43: wfs.setWorkflowVersion(version, current.context + '');
44: wfs.getChoices(current.stage, answer);
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line 1
==> 1: sc_req_item_stageGetChoices()
Any help pointing in the right direction would really be appreciated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2016 01:44 PM
It turns out the issue was that I was working on a new workflow and I hadn't checked it in yet, so for the Guest account, it didn't exist yet. Once I checked in the workflow, it started working for everyone. I'm not used to having issues with this, since you can impersonate a user while working on a checked out workflow and ServiceNow makes your checked out workflow available to the user you are impersonating. Testing this in an inbound email action, which I've never had kick off a workflow before, meant that ServiceNow didn't see a connection between my admin user logged in and the guest user that the inbound email action was being run as.
Hopefully this might help someone else who can't figure out what is going wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 07:39 AM
Shawn, could you please post your code and everything you did to make this work? I have a similar problem and would like to see what you did to trigger the workflows.
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 12:00 PM
I included the inbound email action in the original post. What else would you like to see? If you have a specific question, I might be able to help with that is well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 12:38 PM
Shawn, in what versions/situations have you been able to kick off your checked-out workflow with a user other than yourself?
We're up to Helsinki Patch 5 right now, but I've only ever seen my checked-out workflow changes apply to my own account (while everyone else continues to see the most recently published version). This appears to match the current documentation...
Workflow versions: "When a workflow is checked out, changes apply only to the user who has the workflow checked out. Other users can continue to use the published workflow. After the changes are complete, the workflow can be published so that it is available to all users."
If there's anything I can do to get our DEV instance to apply checked out versions to other users, I'd love to try it! (Of course, I bet the publish-only approach is considered a safeguard for other users in case you were editing a workflow directly in your production environment.)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2017 07:57 AM
I don't think there's any way to do this without checking the workflow in, unfortunately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2017 03:34 PM
Okay. I may have actually misread your original statement, and no matter what, I'm just glad that I'm not squandering an opportunity to take advantage of any functionality. Thanks!