- 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 01:53 AM
Hi Mahak,
you can either do this using array split or as per what Jaspal mentioned
don't use space before and after the dot during the index check
var aa = s.substring(0, s.indexOf('.'));
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-25-2020 08:07 AM
Hi Mahak,
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
If not, please let us know if you need some more assistance.
Regards
Ankur
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-25-2020 08:28 AM
Hello Ankur,
Thank you for the reply.
Name is now populating.
I am also running a onbefore transform script to update the name of the Operating system in the target table so that it doesn't create new options due to difference in Naming Convention.
But still it is using the data which is in the source table not setting the one I have set in the script:
(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';
ignore = false;
}
else if( tr =='Oracle Linux Server')
{
target.os = 'Oracle Linux 4/5/6 (64-bit)';
ignore = false;
}
else if(tr =='SUSE Linux Enterprise Server')
{
target.os = 'SUSE Linux Enterprise 11 (64-bit)';
ignore = false;
}
else
{
ignore = true;
}
})(source, map, log, target);
Can you please tell me the mistake I am making in this?
Regards,
Mahak
- 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-30-2020 02:39 AM
Hi Mahak,
I could see you have marked my response as helpful.
Let me know if I have answered your question.
If so, please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.
If not, please let us know if you need some more assistance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader