The CreatorCon Call for Content is officially open! Get started here.

Get output of Script Include into another Script Include

Rakshanda Kunte
Tera Contributor

Hi,

 

I need to call 1 script include output  into another script include.

 

1st Script Include:   getgroup

 

getLabel: function (){
var g = this.getParameter ('sysparm_group');
var gr = new GlideRecord ('table_name');
gr.addQuery('sys_id', g);
gr.query();
if (gr.next())
{
var sysparm_result = gr.name;
gs.info('Group Name is:' + ' ' + sysparm_result);
}
},

 

2nd Script Include:

 

checkd: function() {

var obj = new getgroup();             // called 1st SI
obj.getLabel();                                // called 1st SI function
var grp = obj.getLabel();                // assigning to grp
var m = this.getParameter('sysparm_m');
var task = new GlideRecord('table_name');
task.addQuery('support_group', grp);                 //support_group is getting group from the catalog form
task.addQuery('u_module', m);
task.query();

gs.info('Script include inputs group: ' + grp + ' method: ' + m);

},

 

 

 

Requirement:

I want to get the result of 1st SI in place of 'grp' to show the name of group. 

If I don't have 1st script include it only returns sys_id

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Rakshanda Kunte 

Unless you return the value from function of 1st script include you cannot use this

Update as this

1st script include

getLabel: function (){
var g = this.getParameter ('sysparm_group');
var gr = new GlideRecord ('table_name');
gr.addQuery('sys_id', g);
gr.query();
if (gr.next())
{
var sysparm_result = gr.name;
return sysparm_result;
}
},

 

2nd Script Include:

 

checkd: function() {

var obj = new getgroup();             // called 1st SI
var returnValue = obj.getLabel();                                // called 1st SI function
var grp = returnValue;                // assigning to grp
var m = this.getParameter('sysparm_m');
var task = new GlideRecord('table_name');
task.addQuery('support_group', grp);                 //support_group is getting group from the catalog form
task.addQuery('u_module', m);
task.query();

gs.info('Script include inputs group: ' + grp + ' method: ' + m);

},

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

View solution in original post

9 REPLIES 9

Karan Chhabra6
Mega Sage

Hi @Rakshanda Kunte ,

 

You need to return some value in the 1st script include, so that it gets stored in the 'var grp' in the 2nd script include.

Refer to the code below:

getLabel: function (){
var g = this.getParameter ('sysparm_group');
var gr = new GlideRecord ('table_name');
gr.addQuery('sys_id', g);
gr.query();
if (gr.next())
{
var sysparm_result = gr.name;
gs.info('Group Name is:' + ' ' + sysparm_result);
return sysparm_result;
}
},

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

Hi @Karan Chhabra6 , 

return will show value on the form, but not able to get that value in 2nd script include.

asifnoor
Kilo Patron

Hi,

In this case, you need to pass the parameter to yoru 1st SI function. So modify your first SI like this.

getLabel: function (group){
//var g = this.getParameter ('sysparm_group');
var g = JSUtil.nil(group) ? this.getParameter("sysparm_group") : group; 
var gr = new GlideRecord ('table_name');
gr.addQuery('sys_id', g);
gr.query();
if (gr.next())
{
var sysparm_result = gr.name;
gs.info('Group Name is:' + ' ' + sysparm_result);
return sysparm_result.toString();
}
},

Then in your 2nd SI, you can call this SI and pass the group sys id parameter 

checkd: function() {
//var obj = new getgroup();             // called 1st SI
//obj.getLabel();                                // called 1st SI function
var grp = new getgroup().getLabel("GROUP SYS ID");                // Pass the group sys id.
var m = this.getParameter('sysparm_m');
var task = new GlideRecord('table_name');
task.addQuery('support_group', grp);                 //support_group is getting group from the catalog form
task.addQuery('u_module', m);
task.query();

gs.info('Script include inputs group: ' + grp + ' method: ' + m);

},

Mark the comment as a correct answer and also helpful if this has answered the question.

 

Hi @asifnoor ,

 

I need to call 1st Script Include result in 2nd SI.