- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2022 12:32 PM
Greeting!!
I have built a script Include that fetch the Software Entitlements information for the Assigned Users.
I have a Termination Catalog, when request is raised from the Catalog, the workflow checks if 'X' has a software license assigned and it creates a Software revoke Task with the Software Entitlement informations on the sc_task description box, This works fine when request is submitted from the Catalog.
But when I submit a request using Transform Map the Software entitlement information for the assigned user is blank on the sc_task description box.
I am using Transform Script Onbefore : Any Help Would be higly appreciated!!
Transform Script Onbefore Looks like this:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Call Script Include
var obj = new DataFilter(); // This is my Script Include
answer = obj.user_sys_id();
// Check if this is an existing user, if userID was provided
var user_sys_id = '';
var user_login_id = '';
var user_location = source.u_location.toString();
if (source.u_emp_.toString() != ''){
var userGR = new GlideRecord('sys_user');
userGR.addQuery('employee_number', source.u_emp_.toString());
userGR.addQuery('active', true);
userGR.query();
if (userGR.next())
{
user_sys_id = userGR.sys_id;
user_login_id = userGR.user_name;
//user_location = userGR.location.name;
}
}
var cart = new sn_sc.CartJS();
var request =
{
'special_instructions' : '',
'requested_for' : 'xxxxxxxxxxxxxxx',
'delivery_address' : "",
};
var item =
{
'sysparm_id': 'yyyyyyyyyyyyyyyyyyyy',
'sysparm_quantity': '1',
'variables':{
'requested_for': 'xxxxxxxxxxxxxxxx',
'employee_name': user_sys_id.toString(),
'login': user_login_id.toString(),
'location': user_location.toString(),
'employee_name': source.u_name.toString(),
'company': source.u_company.toString(),
'title': source.u_title.toString(),
'employee_number': source.u_emp_.toString(),
'employee_manager': source.u_supv.toString(),
'last_working_day': source.u_last_day_worked.toString(),
}};
var cartDetails = cart.addToCart(item);
var requestDetails = cart.submitOrder(request);
ignore = true;
})(source, map, log, target);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2022 10:39 AM
Hello,
Just so we're on the same page, your question was asking how to call a script include from a transform map?
I believe that has been answered by my post above. This is for any future readers who are seeing you reply back which may accidentally indicate to them that what I've mentioned doesn't work, when it does.
You are now asking a 2nd question about passing parameters from your transform map to your script include that you're instantiating.
If you're trying to pass a source record's value, then you'd use:
var scriptInc = new scriptIncludeName().functionName(source.field_name);
var scriptInc = new scopeName.scriptIncludeName().functionName(source.field_name);
Feel free to refer to documentation as well for a bit of assistance: https://docs.servicenow.com/bundle/rome-platform-administration/page/script/server-scripting/referen...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2022 12:55 PM
Hi,
Please use the appropriate forum feature: "Insert/Edit Code sample" when pasting code on the forums. This makes it easier to read instead of a wall of text:
I'm failing to see where you are setting the description with any information?
Also, I'm unsure if this is where you're calling the script include AND you included the script include actual script? Your post is a bit confusing in that regard.
I also don't see any log statements to show where you're troubleshooting things, etc.
Can you perhaps give more information, answer those questions, conduct some troubleshooting, etc. and let us know?
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2022 01:17 PM
Hey Apology for the pasting the script.
To Answer to your questions :
I'm failing to see where you are setting the description with any information?
The Description is set on the Workflow.
where you're calling the script include AND you included the script include actual script?
No this is not my script Include, it is Onbefore Script from Transform Map.
This part is where I am trying to call my script include DataFilter() not sure if the syntax is fine ?
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Call Script Include
var obj = new DataFilter(); // This is my Script Include
answer = obj.user_sys_id();
Clearing my ask, I want to call the script include on the Onbefore Tranform script.
Can we call a script include from Transform map script, if Yes could you guide me.
Thanks for your quick response!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2022 01:29 PM
Hi,
Ok, thanks for answering and yes, it's probably better to just focus directly on the relevant content.
You should be able to call a script include in an onBefore transform map script, it's all server side accessible. I would recommend refraining from using "answer" as it's a reserved word (unless you're intentionally using it). You should be able to simply use:
Depending on the scope of the transform map (if out of scope, you need to include scope name in the script include instantiation AS WELL AS ensure that this script include is accessible from outside your scope)...but if it's all in the same scope you'd use:
var scriptInc = new scriptIncludeName().functionName();
var scriptInc = new scopeName.scriptIncludeName().functionName();
Simple as that. Two examples above. Then scriptInc holds the return value from your script include and that script include would have been executed and done 'x'.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2022 05:01 AM
// As per your instruction I have used this syntax on my Onbefore transform map
var scriptInchw = new DataFilter().getDetails(user_sys_id); // Scroll down for the full script.
But it gives in all the records from the alm_hardware table, I just need records for the queried user, any light on this please ?
// This is my Script Include
var DataFilter = Class.create();
DataFilter.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function(){
var obj = {};
obj.assettag = ''; // Asset Tag
obj.srlno = ''; // Serial Number
obj.modcat = ''; // Model Category
obj.dn = ''; // Display Name
obj.assgto = ''; // Assigned To
obj.inst = ''; // State
obj.subst = ''; // Substate
obj.cst = ''; // Cost
obj.loc = ''; // Location
obj.stroom = ''; // Stock Room
obj.config = ''; // Configuration Item
obj.mod = ''; // Model
obj.clas = ''; // Class
var sysId =this.getParameter('sysparm_sysId');
//var sysId = '00ad3d56db34bc40657ef92b5e9413c9'; // Pulls records for this user.
gs.log("sysId=" + sysId); // This print all the records from alm_hardware table.
var gr = new GlideRecord('alm_hardware');
gr.addQuery('assigned_to', sysId);
gr.query();
while(gr.next()){
if(obj.assettag == ''){
obj.assettag = gr.asset_tag.toString();
}
else{
obj.assettag = obj.assettag + ',' + gr.asset_tag.toString();
}
if(obj.srlno == ''){
obj.srlno = gr.serial_number.toString();
}
else{
obj.srlno = obj.srlno + ',' + gr.serial_number.toString();
}
if(obj.modcat == ''){
obj.modcat = gr.model_category.getDisplayValue();
}
else{
obj.modcat = obj.modcat + ',' + gr.model_category.getDisplayValue();
}
if(obj.dn == ''){
obj.dn = gr.display_name.toString();
}
else{
obj.dn = obj.dn + ',' + gr.display_name.toString();
}
if(obj.assgto == ''){
obj.assgto = gr.assigned_to.toString();
}
else{
obj.assgto = obj.assgto + ',' + gr.assigned_to.toString();
}
if(obj.inst == ''){
obj.inst = gr.install_status.getDisplayValue();
}
else{
obj.inst = obj.inst + ',' + gr.install_status.getDisplayValue();
}
if(obj.subst == ''){
obj.subst = gr.substatus.toString();
}
else{
obj.subst = obj.subst + ',' + gr.substatus.toString();
}
if(obj.cst == ''){
obj.cst = gr.cost.toString();
}
else{
obj.cst = obj.cst + ',' + gr.cost.toString();
}
if(obj.loc == ''){
obj.loc = gr.location.toString();
}
else{
obj.loc = obj.loc + ',' + gr.location.toString();
}
if(obj.stroom == ''){
obj.stroom = gr.stockroom.toString();
}
else{
obj.stroom = obj.stroom + ',' + gr.stockroom.toString();
}
if(obj.config == ''){
obj.config = gr.ci.getDisplayValue();
}
else{
obj.config = obj.config + ',' + gr.ci.getDisplayValue();
}
if(obj.mod == ''){
obj.mod = gr.model.getDisplayValue();
}
else{
obj.mod = obj.mod + ',' + gr.model.getDisplayValue();
}
if(obj.clas == ''){
obj.clas = gr.sys_class_name.toString();
}
else{
obj.clas = obj.clas + ',' + gr.sys_class_name.toString();
}
}
return JSON.stringify(obj);
},
type: 'DataFilter'
});
// This is my Onbefore Transform Map
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Check if this is an existing user, if userID was provided
var user_sys_id = '';
var user_login_id = '';
var user_location = source.u_location.toString();
if (source.u_emp_.toString() != ''){
var userGR = new GlideRecord('sys_user');
userGR.addQuery('employee_number', source.u_emp_.toString());
userGR.addQuery('active', true);
userGR.query();
if (userGR.next())
{
user_sys_id = userGR.sys_id;
user_login_id = userGR.user_name;
//user_location = userGR.location.name;
}
}
var cart = new sn_sc.CartJS();
var request =
{
'special_instructions' : '',
'requested_for' : 'xxxxxxxxxxxxxxx',
'delivery_address' : "",
};
var item =
{
'sysparm_id': 'yyyyyyyyyyyyyyyyyyyy',
'sysparm_quantity': '1',
'variables':{
'requested_for': 'xxxxxxxxxxxxxxxx',
'employee_name': user_sys_id.toString(),
'login': user_login_id.toString(),
'location': user_location.toString(),
'employee_name': source.u_name.toString(),
'company': source.u_company.toString(),
'title': source.u_title.toString(),
'employee_number': source.u_emp_.toString(),
'employee_manager': source.u_supv.toString(),
'last_working_day': source.u_last_day_worked.toString(),
}};
// Call Script Include
var scriptInchw = new DataFilter().getDetails(user_sys_id);
gs.log("scriptInchw-Test" + scriptInchw); // Print All records, I need to fetch records for the queried user.
var cartDetails = cart.addToCart(item);
var requestDetails = cart.submitOrder(request);
ignore = true;
})(source, map, log, target);