Create a record in a customized table when servicenow recieves some data via integeration

Udit5
Tera Contributor

Hi All,

 

I have one requirement that I need to create a new table which will have 5 fields , for ex (A,B,C1,D,E) fields.

Servicenow is getting some data from 3rd party via integration in XML format.

Interagration connection is already in placed, xml path is also there.

 

Th new changes are is that there are new tags in the xml file now which needs to be mapped to these new fields.

xml path will look like this

 

<Description>

<A>ahudhsasa</A>

<B>idhifdhi</B>

<C>

<C1>udhdsiukaa</C1>

</C>

<D>jshdifhidshid</D>

<E>hidhdihdis</E>

</Description>

 

All these values needs to be mapped with the new fields on the table.

 

Can anyone please suggest me some ways to do this?

 

I know script include could be the way to go but can someone help me in what script can I write.?

 

Any reference or approach would be helpful.

 

Thank you in advance 🙂 

2 REPLIES 2

Subhashis Ratna
Tera Guru

Hi @Udit5 

Could you please share your script or some screenshots for reference?

Thanks
Subhashis r7

Subhashis Ratna
Tera Guru

Hi @Udit5  

When addressing specific business requirements involving XML data parsing in ServiceNow, consider utilizing the XMLDocument2 JavaScript object.

Below is an example script for a Script Include that efficiently handles XML data:

 

Script Inlcude Code :

var XMLParser = Class.create();

XMLParser.prototype = {
    initialize: function(xmlString) {
        this.xmlDoc = new XMLDocument2();
        this.xmlDoc.parseXML(xmlString);
    },

    getXMLdata: function(xpath) {
        return this.xmlDoc.getXMLString(xpath);
    }
};


//To use the "getXMLdata" function from your XMLParser script include on the server side (such as in a Business Rule, Script Include, or other server-side script), you can create an instance of XMLParser and then call the "getXMLdata" method. Here's an example:

// I took this XML string from Documentation 

var xmlString = "<test>" +
    "  <one>" +
    "    <two att=\"xxx\">abcd1234</two>" +
    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
    "    <two>another</two>" +
    "  </one>" +
    "  <number>1234</number>" +
    "</test>";

// Create an instance of XMLParser
var xmlParser = new XMLParser(xmlString);

// Get values from XML
var valueOneTwo = xmlParser.getXMLdata('one/two');
var valueOneThree = xmlParser.getXMLdata('one/three');
var valueNumber = xmlParser.getXMLdata('number');

// Log or use the values as needed
gs.info('Value of one/two: ' + valueOneTwo);
gs.info('Value of one/three: ' + valueOneThree);
gs.info('Value of number: ' + valueNumber);

//Here you can update a record in a ServiceNow table
current.one_two = valueOneTwo;
current.one_three = valueOneThree;
current.number = valueNumber;

// Save the record
//You can use setWorkflow(false) based on your logic
current.update();

 


 If you have any more requests or need further clarification, feel free to let me know!

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.


Thank you!
Subhashisr7