Skip to content

Conversation

prithvibalakka
Copy link
Contributor

This function, getRecordXML, is a custom JavaScript function designed for ServiceNow to generate an XML representation of a record in any specified table.

Copy link

@wiz0floyd wiz0floyd left a 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?

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

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');

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();

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) {

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++) {

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());

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);

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);

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();

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.

@wiz0floyd wiz0floyd closed this Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants