How to create record in table from JSON response

Balaji Munusamy
Tera Contributor

@Ankur Bawiskar Could you please assist me on this?

1 ACCEPTED SOLUTION

Omender Singh
Tera Guru

To create a record in a service table from a JSON response, you will need to follow these general steps:

1. Parse the JSON response: Use a JSON parser to convert the JSON response
2. Extract the relevant data
3. Connect to the service table
4. Insert the data

------------------------------------------------------------------
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = {
initialize: function() {},

createRecordFromJSON: function(jsonResponse) {
var responseObj = JSON.parse(jsonResponse);

var name = responseObj.name;
var email = responseObj.email;
var age = responseObj.age;

var gr = new GlideRecord('your table');
gr.initialize();

gr.name = name;
gr.email = email;
gr.age = age;

gr.insert();
}
};

 

// Usage example
var jsonResponse = '{"name": "John Doe", "email": "john.doe@example.com", "age": 30}';
var myScriptInclude = new MyScriptInclude();
myScriptInclude.createRecordFromJSON(jsonResponse);

 

---------------------------------------------------------------------

 

 

Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!

 

I invite you to checkout  below  items for more interesting and knowledgeful ServiceNow stuff.

View solution in original post

2 REPLIES 2

Omender Singh
Tera Guru

To create a record in a service table from a JSON response, you will need to follow these general steps:

1. Parse the JSON response: Use a JSON parser to convert the JSON response
2. Extract the relevant data
3. Connect to the service table
4. Insert the data

------------------------------------------------------------------
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = {
initialize: function() {},

createRecordFromJSON: function(jsonResponse) {
var responseObj = JSON.parse(jsonResponse);

var name = responseObj.name;
var email = responseObj.email;
var age = responseObj.age;

var gr = new GlideRecord('your table');
gr.initialize();

gr.name = name;
gr.email = email;
gr.age = age;

gr.insert();
}
};

 

// Usage example
var jsonResponse = '{"name": "John Doe", "email": "john.doe@example.com", "age": 30}';
var myScriptInclude = new MyScriptInclude();
myScriptInclude.createRecordFromJSON(jsonResponse);

 

---------------------------------------------------------------------

 

 

Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!

 

I invite you to checkout  below  items for more interesting and knowledgeful ServiceNow stuff.

Ankur Bawiskar
Tera Patron
Tera Patron

@Balaji Munusamy 

how the json looks like?

you can parse the json and iterate and then insert

what did you start with?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader