- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
09-27-2020 12:54 AM - edited 07-20-2025 07:21 PM
Have you wondered if you can use GlideRecord in MID Server Script Include? Yes, you can.
Most of the articles will talk about using the REST APIs (Package calls) but we can simply use GlideRecord instead.
Snippet:
Navigate to MID Server > Script Includes. Click New, fill out the fields below, and Save.
Name: UpdateSNRecordUtil
Script:
var UpdateSNRecordUtil = Class.create();
UpdateSNRecordUtil.prototype = {
initialize: function() {},
updateRecord: function() {
var table = probe.getParameter("table"); // incident
var recSysId = probe.getParameter("sysId");
var gr = new GlideRecord(table);
if (gr.get(recSysId)) {
gr.work_notes = "Record Updated from MID Server Script";
gr.update();
}
},
type: UpdateSNRecordUtil
};
You can call the MID Server script include using JavascriptProbe from any server side script (Business Rule/UI Action/Script Include)
var jspr = new JavascriptProbe(MID_SERVER_NAME);
jspr.setName('Test');
jspr.setJavascript('var util = new UpdateSNRecordUtil(); util.updateRecord();');
jspr.addParameter("sysId", RECORD_SYS_ID); // 932da724dba31010bfb5a0f2ca96196a
jspr.addParameter("table", TABLE_NAME); // incident
jspr.create();
- 2,786 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Chirag,
I tried the above script, but it is saying that MID_SERVER_NAME is not found.
I have searched all script includes but I didn't find any variable termed MID_SERVER_NAME.
I tried giving my mid server name also, but it didn't worked out.
Can you please help me in solving this issue.
Thank you.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Roshan Apuru - my bad, I forgot to mention that you need to assign MID_SERVER_NAME variable with actual mid server name.
as you mentioned that you already tried with mid server name but it didn't work for you.
Can you help me with below information;
1. Are you testing on PDI? If yes, can you share the instance URL
2. The instance is on which ServiceNow release?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Chirag,
Thank you so much for the reply.
I tried giving MID_SERVER_NAME as "mid_roshan". (Name of the mid server I am currently using).
It says this error :
JAVASCRIPT_CODE_FAILURE: Java constructor for "com.service_now.mid.probe.JavascriptProbe" with arguments "string" not found. (script_include:AzureApiCommand; line 80).
Yes, I am working on PDI instance.
PDI instance URL : https://roshanapuru.service-now.com/now/nav/ui
The instance is on Utah release.
Thanks,
Roshan
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I checked PDI instance and I think, the possible reason why GlideRecord() is not working for you is because JavascriptProbe is not supported for scoped apps.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
JavaScriptProbe was not accessible from scoped apps hence I tried updating accessible from field for JavaScriptProbe & ProbeScriptPreexecute script includes but then GlideRecord always returned zero results so, it didn't work for me.
Maybe you can try using it in Global Scope.