- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 01:41 AM
Hello guys,
I have a requirement according to which i need to change the field to Uppercase and then remove some characters from the String field after the certain character and put it into the different field .
For Ex :
Input:
Name : abcde.pqr@stu
Output:
Name:ABCDE
Dom:PQR@STU
In short the characters after " . " should be removed from the first field.
I have written a code in transform field map script to change the string to UpperCAse and remove the characters after fullstop.But it is not working.
answer = (function transformEntry(source) {
// Add your code here
var t = source.name.toString();
var s = t.toUpperCase();
var aa = s.substring(0, s.indexOf(' . '));
return aa; // return the value to be put into the target field
})(source);
Can anyone help in this?
Regards,
Mahak
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2020 08:42 AM
Hi,
So the target field is choice type and hence you are using if else statements
you should do this in field map script and not onbefore
Field Map Script:
answer = (function transformEntry(source) {
// Add your code here
var tr = source.u_operation_system.toString();
if(tr == 'Red Hat Enterprise Linux Server')
{
return 'Red Hat Ent Linux';
}
else if(tr == 'Oracle Linux Server')
{
return 'Oracle Linux 4/5/6 (64-bit)';
}
else if(tr == 'SUSE Linux Enterprise Server')
{
return 'SUSE Linux Enterprise 11 (64-bit)';
}
})(source);
if you want transform script then use this
(function runTransformScript(source, map, log /*undefined onStart*/ ) {
var tr = source.u_operation_system.toString();
if( tr =='Red Hat Enterprise Linux Server')
{
target.os = 'Red Hat Ent Linux';
}
else if( tr =='Oracle Linux Server')
{
target.os = 'Oracle Linux 4/5/6 (64-bit)';
}
else if(tr =='SUSE Linux Enterprise Server')
{
target.os = 'SUSE Linux Enterprise 11 (64-bit)';
}
else
{
ignore = true;
}
})(source, map, log, target);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 02:19 AM
If you want to set 2 fields (name and dom), you need to add 2 scripts. 1 for each field.
For name use:
returns ABCDE
answer = (function transformEntry(source) {
var t = source.name.toString();
t = t.toUpperCase();
t = t.split('.')[0];
return t; // return the value to be put into the target field
})(source);
For dom use:
returns PQR@STU
answer = (function transformEntry(source) {
var t = source.name.toString();
t = t.toUpperCase();
t = t.split('.')[1];
return t; // return the value to be put into the target field
})(source);