Get substring after backslash in a string

HarshTimes
Tera Guru

hi
I have a string that contains a backslash.I want the substring after backslash. How can i get it?I tried substring function but its not working.PLease help me out.
example if the string is "first\last" I want to store 'last' in a variable.

14 REPLIES 14

Hi,
I have only one backslash in my string and this string is coming from SCCM.Yes, its looking simple to split this string but its not.for the double backslash \\ its working fine,but i need the solution for the single backslash '\'.


its not a double slash. its a single slash, you are escaping it using another slash.


garyopela
ServiceNow Employee
ServiceNow Employee

Hi, I ran into the same thing. I'm pulling the last logon from SCCM into Service-Now. On the "SMS / SCCM Computer System" data source, the transform map is "SMS Computer_System_DATA" in the SCCM version 2 plugin out of the box. I have added a field called u_lastlogon to capture the last logged in user from SCCM.

I have an onBefore transform script that sets the u_lastlogon field with the following:

var uname = source.u_username0.toString();
var names = uname.split("\\");
if (names.length == 2) {
source.u_username0 = names[1];
}

You escape in the javascript, you don't have to alter what SCCM stores. For instance, SCCM would have domain\user in this column, I am splitting on \ but you have to escape it in your javascript with \\.

You could probably also set it via a script in your transform mapping as well. I'm not sure why I used an onBefore transform script on this.


Hi Gary,



I am trying to implement Last Login user and Date/time feature in ServiceNow. Could you please confirm which tables captures this information or if you could provide me the query you used.



I am using SCCM 2012.



Regards,


N Dubey


lilianm_vel
Kilo Contributor

I had some problem using the substr(n, m) function. Use the substring(n, m) function and it's working fine.