The CreatorCon Call for Content is officially open! Get started here.

Creating Request via inbound action is skipping request numbers

rlehmann
Kilo Sage

Running on London Patch 4 Hot Fix 2.
Created a new inbound action to create a request ticket based on specific criteria.
It has been set as the lowest order inbound action and the "stop processing" check box has been selected.
There are no other inbound actions that target the Request [sc_request] table.
According to the logs, it appears that the system is processing my inbound email message twice, skipping it on the first pass and then creating the request on the second. find_real_file.png I suspect this may be what is causing the REQ numbers to be skipped. In this example, I already have REQ0053770 and expect the inbound action to create REQ0053771, but instead creates REQ0053772, with no record of there ever being a REQ0053771.
The request is being created correctly, but it shouldn't be skipping request numbers during the process.
Here is a copy of the inbound action script running:

createRequest();

function createRequest() {
	// setup variables
    var short_description = email.subject.toString();
	var body = email.body_text.toString();	
	var message = "received from: " + email.origemail + "\n\n" + body;
	var cat_item = 'e2e6fb3d1b0cf7406ec2a82fbd4bcbc3'; // my catalog item sys_id
	var requested_for = email.origemail;
	
	var cart = new sn_sc.CartJS();
	//var cart = new Cart();
	var item =
		{
			'sysparm_id': cat_item,
			'sysparm_quantity': '1',
			'variables': {
				'notes': message
			}
		};
	cart.addToCart(item);
	
	var request =
	{
	  //'special_instructions' : '',
	  'requested_for' : requested_for,
	  //'delivery_address' : '',
	};
	// Place order from cart
	var requestDetails = cart.submitOrder(request);
	//var requestDetails = cart.checkoutCart();

	// update details in the Requested Item
	// pull out the Request Sys ID from the order
	var reqSysID = requestDetails.request_id;

	// update the RITM to have a short description from the email
	var rec = new GlideRecord('sc_req_item');
	rec.addQuery('request', reqSysID);
	rec.query();
	// check for a record
	if (rec.next()) {		
		// get the RITM, should be the only item with this parent
		rec.short_description = short_description;
		rec.comments = message;
		rec.update();
	}
	var ritmSysID = rec.sys_id;
	var email_log = new GlideRecord('sys_email');
	email_log.addQuery('uid', email.uid);
	email_log.orderByDesc('sys_created_on');
	email_log.query();
	var email_sys = "";
	if (email_log.next()) {
		email_sys = email_log.sys_id;
		GlideSysAttachment.copy('sys_email', email_sys, 'sc_req_item', ritmSysID);
	} else {
		email_sys = 0;
		GlideSysAttachment.copy('sys_email', email_sys, 'sc_req_item', ritmSysID);
	}
}

Anyone have any suggestions as to why the request numbers are skipping?

As always, thanks for any and all assistance.

Cheers!
Ron

6 REPLIES 6

I ended up changing my inbound action to run against the Requested Item [sc_req_item} table instead of the request table.
This has stopped the issue if skipping numbers.
Here is a copy of the updated script I ended up using, which also takes any email attachments and adds them to the RITM:

createRequest();

function createRequest() {
	// setup variables
    var short_description = email.subject.toString();
	var body = email.body_text.toString();	
	var message = "received from: " + email.origemail + "\n\n" + body;
	var cat_item = 'e2e6fb3d1b0cf7406ec2a82fbd4bcbc3'; // my catalog item sys_id
	var requested_for = email.origemail;
	
	var cart = new sn_sc.CartJS();
	var item =
		{
			'sysparm_id': cat_item,
			'sysparm_quantity': '1',
			'variables': {
				'notes': message
			}
		};
	cart.addToCart(item);
	
	var request =
	{
	  //'special_instructions' : '',
	  'requested_for' : requested_for,
	  //'delivery_address' : '',
	};
	// Place order from cart
	var requestDetails = cart.submitOrder(request);
	
	// Pull out the Request Sys ID from the order
	var reqSysID = requestDetails.request_id;

	// Update the RITM to have a short description from the email
	var rec = new GlideRecord('sc_req_item');
	rec.addQuery('request', reqSysID);
	rec.query();
	// check for a record
	if (rec.next()) {		
		// get the RITM, should be the only item with this parent
		rec.short_description = short_description;
		rec.comments = message;
		rec.update();
	}
	
	var ritmSysID = rec.sys_id;
	var email_log = new GlideRecord('sys_email');
	email_log.addQuery('uid', email.uid);
	email_log.orderByDesc('sys_created_on');
	email_log.query();
	var email_sys = "";
	if (email_log.next()) {
		email_sys = email_log.sys_id;
		GlideSysAttachment.copy('sys_email', email_sys, 'sc_req_item', ritmSysID);
	} else {
		email_sys = 0;
		GlideSysAttachment.copy('sys_email', email_sys, 'sc_req_item', ritmSysID);
	}
}

Hopefully this will help you.

Inactive_Use407
Giga Contributor

Thanks for your quick return.

Doubt: the request is generated too or only requested item?

I was able to fix it by changing the property glide.itil.assign.number.on.insert to true, but this way, when loading the form to create any record the number field is empty.