- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 04:49 AM
Issue: I need to create multiple record in Snow system at a time through Scripted REST API. Any idea how to achieve this solution?
Scenario: There is a record A which has table name X.
Again there is record B and table name Y, but record B is present in the related list of record A, for example Approval field is present is related list of RITM.
Expected sol: I need to create 100 records for B,
That 100 record's Name should be 100, 102,103.... and up to 200.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 06:04 AM
Maybe I'm missing something here. If you are developing the Scripted Rest API on your instance, the code can include pretty much anything you would like. All you need is to have a way for your code to know what needs to be part of the table B rows. Something like this:
var tableARecord = new GlideRecord("tableA");
//Set the values
var newTableA = tableARecord.insert();
for (var i = 0; i < 100; i++) {
var tableBRecord = new GlideRecord("tableB");
tableBRecord.setValue("name", i);
tableBRecord.setValue("<reference field>", newTableA.sys_id);
//set any other values
tableBRecord.insert();
}
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 06:04 AM
Maybe I'm missing something here. If you are developing the Scripted Rest API on your instance, the code can include pretty much anything you would like. All you need is to have a way for your code to know what needs to be part of the table B rows. Something like this:
var tableARecord = new GlideRecord("tableA");
//Set the values
var newTableA = tableARecord.insert();
for (var i = 0; i < 100; i++) {
var tableBRecord = new GlideRecord("tableB");
tableBRecord.setValue("name", i);
tableBRecord.setValue("<reference field>", newTableA.sys_id);
//set any other values
tableBRecord.insert();
}
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 10:04 AM
Hi
Thanks for the response.
It is working with Rest API.
But according to business requirement i need to define the logice in script include first then need to call that script include in REST API.
in short i have to develop this through script include and REST API.
do you know how to do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 11:30 AM
Hi VJ,
That's not hard. Having the functionality in a script include makes your code much more reusable. Keep in mind that a script include defines a class so there's a lot you can do with them. For now, let's look at a simple setup.
When you create a script include you get a framework pre-built that includes a generic constructor. In many cases that is sufficient. From there you build functions:
var MyNewScriptInclude = Class.create();
MyNewScriptInclude.prototype = {
initialize: function() {
},
myFirstFunction : function(param1, param2) {
var a = this.mySecondFunction(param2);
return a.toUpperCase();
},
mySecondFunction : function(param1, param2) {
return param2 + param1.substring(0,5);
},
type: 'MyNewScriptInclude'
};
This is obviously a very simple case but should give you the idea. myFirstFunction and mySecondFunction are all that I added to the basic script. (you are free to name the script and the functions as you see fit)
One thing that can drive you nuts when first working with script includes is that you need the comma after the closing curly brace that defines the function. You can have as many functions as you need in a script include.
When one function in a script include calls another you need the this qualifier.
Having that in place, you simply need to instantiate an instance of your script include and access whatever function you need. This is what it would look like in your scripted REST API:
var theScript = new myNewScriptInclude();
var theResult = theScript.myFirstFunction("abcdwxyz","123459876");
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 03:43 AM
Hi John,
As this is new to me.
Could you please frame the script include and rest api according to my business requirement just like you first answer.