how to insert a record from back ground script through JSON format? in incident…
- User
how to insert a record from back ground script through JSON format? in incident tableservicenow
- Assistant
To insert a record into the Incident table in ServiceNow using a background script and JSON format, you need to have the data you want to insert structured as a JSON object. Then, you can use this JSON object to populate a new GlideRecord instance and insert it into the database. Here's a step-by-step guide:
1. Log into ServiceNow:
First, make sure you are logged into your ServiceNow instance.
2. Navigate to Scripts - Background:
Go to
System Definition > Scripts - Backgroundin the navigator. This is where you can execute arbitrary server-side scripts that interact with the database.3. Structure Your Data as JSON:
Decide on the fields you want to insert into the Incident table and structure them in JSON format. For example:
json{ "short_description": "Sample Incident", "urgency": "2", "impact": "2", "category": "software", "subcategory": "email", "assignment_group": "287ebd7da9fe198100f92cc8d1d2154e", // Example Sys ID of an Assignment Group "assigned_to": "9eecfbd7a9fe198100f92cc8d1d2154e" // Example Sys ID of a User }4. Write the Script to Insert the Record:
In the Scripts - Background module input area, write a script that:
- Parses the JSON object,
- Creates a new GlideRecord for the Incident table,
- Assigns the values from the JSON object to the new record, and
- Inserts it into the database.
Here is how the script could look:
javascript - User
I need to print the list of incident as a modal in SOW when we select caller from caller field in an incident form, is it a good approach
- Assistant
- User
I need to print the list of incident as a modal in SOW when we select caller from caller field in an incident form, give me exact solution
- Assistant
- User
I have a requirement where a change request goes through 4 level of approvals , first from the ag approval , second from Configuration item AG approval third from the Change Request.AG approval and fourth one from Change Request Approval.AG approval .
so if the requested by or assigned to is a member of any of the above mentioned 4 AG approval group it should show the state as "not required" for those members in all the 4 AG approval levels
the first two approval groups first from the ag approval , second from Configuration item AG approval is managed by this part of code : (current.sysapproval.requested_by.sys_id == current.approver.sys_id || current.sysapproval.assigned_to.sys_id == current.approver.sys_id and it is working perfectly fine
How to manage the scenario where the requested by or assigned to is a member of the Change Request.AG or Change Request Approval.AG -- this code is not working
create a business rule for it
- Assistant
- User
The BR is writted on the sysapproval_approver table and its an after insert BR . Script : var usr= current.approver.sys_id; var mbr =[]; var mbr2 =[]; var grp = new GlideRecord('sys_user_grmember'); grp.addQuery('group', '67598c756f6a6100800e9eff6f3ee4e5');//Change Request.AG grp.addQuery('user', usr); grp.query(); while(grp.next()){ mbr.push('yes'); }
var grp2 = new GlideRecord('sys_user_grmember'); grp2.addQuery('group', 'f37d1d6adb57e050d407da75ca9619e7');//Change Request Approval.AG grp2.addQuery('user', usr); grp2.query(); while(grp2.next()){ mbr2.push('yes'); } if(current.sysapproval.requested_by.sys_id == current.approver.sys_id || current.sysapproval.assigned_to.sys_id == current.approver.sys_id && mbr =='' && mbr2 ==''){ current.state = 'not_required'; current.update(); }
Is this correct or your one??
- Assistant