REST API and Business Rules

Michael Wheatle
Kilo Explorer

I’m working with a group that is using ServiceNow, but has limited developer resources to provide information on it. I’m not entirely sure what I need to ask, but I was directed here to try and get some idea of what I need to know and investigate. I know very little about SNow at this point, so that is a thing.

We are attempting to feed data into a ServiceNow via the REST API. By in large it has been working, but in one case we are running into a situation with a Business Rule script on insert aborting the insert. I managed to track the script down and use logging to dump the data passed into it, so I know why it’s failing, but I don’t really know enough around what is happening or how things get to get to the script to feel like I can do something about it.

Asking around we believe it is an out of the box script on the proc_po_item table by the name of "Model Category of Model not empty." Looks like this:

function onBefore(current, previous) {	
//  This function will be automatically called when this rule is processed.
	if (!current.model.cmdb_model_category) {		
		var message = gs.getMessage("The Product Model \"{0}\" does not have a Model Category", current.model.name); 
		gs.addErrorMessage(message);
		current.setAbortAction(true);
	}
}

When the data is coming from the API current doesn’t really have any meaningful data in it. “model” exists, but is empty as is everything else. So, model exists but has no properties at all. Check fails. I have confirmed we are sending the sys_id for a valid cmbd_model. I’m guessing the model data isn’t loaded just because I sent a key for one, but the script is assuming the data is there. I don't really know what all SNow is doing with my data by the time it gets to the script.

The current UI doesn't seem to trigger the script at all. I could just remove the thing, but I really don't know what I "should" do. Any pointers to relevant resources would be appreciated.

 

1 REPLY 1

Michael Wheatle
Kilo Explorer

Well, I found some formatting issues that seems to have been the cause of my problem. I guess I'm ok after all.