-
Notifications
You must be signed in to change notification settings - Fork 694
getRecordXML Function #1507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getRecordXML Function #1507
Changes from all commits
96a196e
546ef1c
53e7197
95b8d4a
c2cfa14
9ad52c6
11d720a
6a6733e
7bd0d1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function getRecordXML(tableName, sysId) { | ||
var gr = new GlideRecord(tableName); // Replace 'incident' with your table name | ||
gr.get(sysId); | ||
var xmlDoc = new XMLDocument(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of building the xml manually, there is an object to xml script available out of the box. |
||
var baseTag = xmlDoc.createElement('incident'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be the table name, not static value of incident? |
||
var fields = gr.getFields(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a valid glide record method. There is a get fields method in glide record util. |
||
|
||
var fieldNames = []; | ||
for (var i = 0; i < fields.size(); i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is fields.size()? |
||
fieldNames.push(fields.get(i).getName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is |
||
} | ||
fieldNames.sort(); | ||
|
||
fieldNames.forEach(function(fieldName) { | ||
var fieldValue = gr.getValue(fieldName); | ||
var fieldTag = xmlDoc.createElement(fieldName); | ||
fieldTag.setTextContent(fieldValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a documented method. |
||
baseTag.appendChild(fieldTag); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a documented method |
||
}); | ||
gs.info(xmlDoc.toString()); | ||
return xmlDoc.toString(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This function, getRecordXML, is a custom JavaScript function designed for ServiceNow to generate an XML representation of a record in any specified table. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to be an unintended file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function openinLIST() { | ||
var taskTable = g_form.getTableName(); | ||
|
||
// Construct the hardcoded LIST URL | ||
var listURL = '/' + taskTable + '_list.do?sysparm_clear_stack=true'; | ||
|
||
// Open in new window | ||
var w = getTopWindow(); | ||
w.window.open(listURL, '_blank'); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to be an unintended file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This UI Action opens the LIST view for the current table in another tab. | ||
UI action will run on Onclick openinLIST() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of taking a table name and sys id, consider taking a GlideRecord as the input. Then you could use it in a business rule by feeding it
current
.