-
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
Conversation
UI Action for Opening the LIST view of current Form Table
Add files via upload
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.
Thank you for your submission. There are a number of things that need to be addressed. Out of curiosity, where did you find some of the methods you're using?
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.
This appears to be an unintended file
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.
This appears to be an unintended file
var gr = new GlideRecord(tableName); // Replace 'incident' with your table name | ||
gr.get(sysId); | ||
var xmlDoc = new XMLDocument(); | ||
var baseTag = xmlDoc.createElement('incident'); |
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.
Shouldn't this be the table name, not static value of incident?
gr.get(sysId); | ||
var xmlDoc = new XMLDocument(); | ||
var baseTag = xmlDoc.createElement('incident'); | ||
var fields = gr.getFields(); |
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.
This is not a valid glide record method. There is a get fields method in glide record util.
@@ -0,0 +1,22 @@ | |||
function getRecordXML(tableName, sysId) { |
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
.
var fields = gr.getFields(); | ||
|
||
var fieldNames = []; | ||
for (var i = 0; i < fields.size(); i++) { |
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.
What is fields.size()?
|
||
var fieldNames = []; | ||
for (var i = 0; i < fields.size(); i++) { | ||
fieldNames.push(fields.get(i).getName()); |
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.
What is fields.get(i).getName()
?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a documented method.
var fieldValue = gr.getValue(fieldName); | ||
var fieldTag = xmlDoc.createElement(fieldName); | ||
fieldTag.setTextContent(fieldValue); | ||
baseTag.appendChild(fieldTag); |
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.
This is not a documented method
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 comment
The 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.
This function, getRecordXML, is a custom JavaScript function designed for ServiceNow to generate an XML representation of a record in any specified table.