- 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-11-2022 06:46 AM
Hi,
I'm simply trying to help you get your script include called within an onBefore transform map. That's what your question is about, right? Have you verified if your script include is being instantiated as per my suggestion?
I'm unsure what "user_sys_id" means as far as what you're passing into the script include.
So let's confirm that your script include is being instantiated from your onBefore transform map per what I suggested...as a starting point.
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-14-2022 09:48 AM
Hi Allen!
When my Transform Map is executed as per your instruction code below.
var scriptInchw = new DataFilter().getDetails(user_sys_id);
// gs.log("scriptInchw-Test" + scriptInchw);
It does bring all the records from the alm_hardware table (as defined on my Script Include).
Looking to see How can I script, to filter only record for the user on my source sheet?
Thanks for your patience and time!

- 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
‎07-20-2023 12:09 AM
Hi, I have a very complicated task where certain columns from the Excel file must be created before assigned to the current Groups I am importing.
Can you advice me where i go wrong. Thank you in advance.
Script Includes:
var transformMapUtils = Class.create();
transformMapUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setGroupMember: function (userId, groupId) {
gs.info('MK ' + 'Set Group started')
var gr = new GlideRecord("sys_user_grmember");
gr.initialize();
gr.user = userId;
gr.group = groupId;
gr.insert();
},
setRole: function(roleId, groupId){
gs.info('MK ' + 'Set role started')
var gr = new GlideRecord("sys_group_has_role");
gr.initialize();
gr.group = groupId;
gr.role = roleId;
gr.insert();
},
createNewUser: function (user) {
function create(data) {
var recordSysID;
var userTable = new GlideRecord("sys_user");
userTable.initialize();
if (Array.isArray(data)) {
var namesToUppercase = data.map(function (name) {
return name.charAt(0).toUpperCase() + name.slice(1);
});
var names = {
firstName: namesToUppercase[0],
lastName: namesToUppercase[1],
};
userTable.user_name = names.firstName.toLowerCase() + names.lastName;
userTable.first_name = names.firstName;
userTable.last_name = names.lastName;
userTable.email = data[0];
userTable.preferred_language = "Bulgarian";
userTable.insert();
recordSysID = userTable.getValue("sys_id");
} else if (typeof data == "string") {
userTable.user_name = data;
userTable.email = data + "@example.com";
userTable.preferred_language = "Bulgarian";
userTable.insert();
recordSysID = userTable.getValue("sys_id");
}
//return newUser || existingUser sys_id
return recordSysID;
}
gs.info('MK ' + 'Create User started')
var regexEmail = /^([^@.]+)\.([^@]+)@.*$/;
var userNameRegex = /^([^@]+)@.*$/;
var userEmail = user.match(regexEmail);
var userName = user.match(userNameRegex);
if (userEmail !== null) {
userEmail = userEmail.slice(1, 3);
return create(userEmail);
} else {
return create(userName[1]);
}
},
findUser: function (user) {
gs.info('MK ' + 'Find User started')
var userTable = new GlideRecord("sys_user");
userTable.query();
while (userTable.next()) {
var currentUser = userTable.getValue("email");
if (currentUser == user) {
var userID = userTable.getValue("sys_id");
return userID;
} else {
return false;
}
}
},
validateUser: function (usersArray) {
gs.info('MK ' + 'Validate User started')
var result = [];
usersArray.forEach(function (user) {
var currentResult = this.findUser(user);
if (currentResult == false) {
var newUserID = this.createNewUser(user);
gs.info("ValidateUser > " + "new user was created " + newUserID);
result.push(newUserID);
} else {
gs.info("ValidateUser > " + "user was found");
result.push(currentResult);
}
});
return result;
},
createNewRole: function (role) {
gs.info('MK ' + 'Create role started')
var roleTable = new GlideRecord("sys_user_role");
roleTable.initialize();
roleTable.name = role;
roleTable.description = "created via transform map";
roleTable.insert();
var roleSysID = getValue("sys_id");
//return newRole || existingRole sys_id
gs.info(roleSysID)
return roleSysID;
},
findRole: function (role) {
gs.info('MK ' + 'Find role started')
var roleTable = new GlideRecord("sys_user_role");
roleTable.query();
while (roleTable.next()) {
var currentRole = roleTable.getValue("name");
if (currentRole == role) {
var userID = roleTable.getValue("sys_id");
return userID;
} else {
return false;
}
}
},
validateRole: function (rolesArray) {
gs.info('MK ' + 'Validate role started')
var result = [];
rolesArray.forEach(function (role) {
var currentResult = this.findRole(role);
if (currentResult == false) {
var newRoleID = this.createNewRole(role);
gs.info("ValidateRole > " + "new role was created " + newRoleID);
result.push(newRoleID);
} else {
gs.info("ValidateRole > " + "role was found");
result.push(currentResult);
}
});
return result;
},
type: "transformMapUtils",
});
Transform map - OnAfter Script:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
try {
gs.info('OnAfter has started')
var users = source.u_members.split(',');
var allNewUsers = new transformMapUtils().validateUsers(users);
allNewUsers.forEach(function(user) {
new transformMapUtils().setGroupMember(user, target.sys_id);
});
var roles = source.u_roles.split(',');
var allNewRoles = new transformMapUtils().validateRoles(roles);
allNewRoles.forEach(function(role) {
new transformMapUtils().setRoles(role, target.sys_id);
});
} catch (ex) {
gs.info('Users transform map onAfter script error: ' + ex.message + ' ' + ex.stack);
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2022 06:54 AM
Since you're calling your Script Include from a server side script, you don't need the 'this.getParameter('sysparm....')' but instead pull in like this:
getDetails: function(sysId)