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 04:58 PM
Hi Greg,
Depending on your specific situation, you want to apply Business Rules for validation, a Data Policy, or neither.
There is nothing inherently incorrect about sending in a record with a blank reference field, or with a reference for a sys_id that doesn't exist.
Consider the case where your web service is sending two incidents- one of which is referenced as the parent of the other. If the child comes in first, and you try to find the parent based on the sys_id provided in the child, you'll reject it- it's not valid. A moment later, the Parent record gets processed in, and that child's reference is suddenly valid.
You will have to decide on a per-field basis whether values are required, or if a validation has to be applied.
Thanks
Cory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 10:08 PM
Hi Greg,
Can you explain little bit briefly about your issue and requirement.
So that we can give you some idea about your problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 07:01 AM
Hi Thangapandyan,
I am using a static WSDL for a client to integrate to ServiceNow. The static WSDL uses a Script Include which houses the logic for creating/updating transactions in the incident table. When creating a new record via script, I would prefer if ServiceNow gave me back any errors that were encountered, like "Invalid assignment group" in the case above, but it just creates the record anyway leaving the invalid value blank on the new record.
I know this can be done naively using web service import sets and "rejecting" invalid reference and/or choice values, but the client needs to use their own WSDL which forced us in the direction of using a Static WSDL, which also forces us to do everything via Script Include (to my knowledge at least).
I know i could validate each value individually prior to creating the record, but that seems pretty cumbersome.
Thanks for the help everybody!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 07:14 AM
Hi Greg,
You can get the data through import set and then you can use the "choice action" concept to create/reject/ignore the reference value.
This field specifies what to do if the import set contains a reference or choice value other than those available.
Please refer the below links for more info.
http://wiki.servicenow.com/index.php?title=Import_Sets
http://wiki.servicenow.com/index.php?title=Creating_New_Transform_Maps#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 09:36 PM
Hi Greg,
This can be achieved from Business rule and Script include file.
Here is the example, I try to insert the new record without duplication and try to update the existing record without duplication, below is code details,
Business Rule:
Name: Prevent duplicate
Name
Table: Table name here
Order: 100
Client callable: false
Active: true
Description:
When: before
Insert: true
Update: true
Business Rule Details:
Condition:
current.groupname !=''
var CI_result = new AvoidEmptygrName().EmptyGrNme(current.grname.toString());
Script Include Details:
Name: AvoidEmptygrName
Active: true
Client callable: true
var AvoidEmptygrName = Class.create();
AvoidEmptygrName.prototype = {
initialize: function() {
},
// Check the duplicate CIs name within a class.
EmptyGrNme: function(gr_name){
var Grpname = gr_name;
var flag=true;
if(Grpname !='')
{
flag=false;
}
if(flag==fales)
{
gs.addInfoMessage("Group name is empty");
current.setAbortAction(true);
}
else
{
gs.addInfoMessage("Record inserted successfully.");
}
};