Validation on GlideRecord.insert()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 02:07 PM
I am curious if there is some type of validation on GlideRecord.insert()?
I.e, running the following code, there is no Assignment Group with this name, but it is still creating the record with the Assignment Group blank.
var gr = new GlideRecord('incident');
gr.initialize()
gr.description = 'Validation test';
gr.assignment_group = 'This does not exist!';
var response = gr.insert();
gs.log('>>>: ' + response);
I am wanting the record to not insert at all and give me a response for the appropriate error. I did not see any GlideRecord methods that seem to make the business rules run when inserting a new record.
Maybe I am missing something, but can anyone help?
Thanks!!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 02:36 PM
You could create a validation Business Rule that runs Before Insert, and aborts the action if assigned_to is empty. Our default functionality, however, will be to insert the record with a null value like you are seeing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 02:43 PM
Thank you, David.
I just wasn't sure if there was a similar type functionality to being able to set "reject" on a transform map field on import. I will give it a try. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 03:09 PM
Hi Greg,
You have to explicitly turn off business rules for a given insert or update- they run by default.
Do you have a "before" business rule that runs on "insert" and validates that field?
You can use a script like:
function onBefore(current, previous) {
//require valid parent references
if(!current.parent.getRefRecord().isValid())
current.setAbortAction(true);
}
This will abort an insert if the parent field contains an invalid sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 04:41 PM
Thank you for the reply Cory.
A little background. I am using a static WSDL for an inbound integration and the scripted web service/script include tied to the WSDL is doing an insert into the incident table. This is where my GlideRecord is running from and was just looking for a way to validate the record before being inserted. I was hoping I would be able to use the native functionality that a web service import set uses as far as validating fields and returning errors to the client rather than having to validate every single field manually.