logo

NJP

ServiceNow Use Case to update the email domain for users | ServiceNow tips and tricks | ServiceNow

Import · Mar 14, 2022 · video

[Music] hi all and welcome back so in today's tutorial we'll be looking at one more use case so yesterday i was discussing with one of my friend and uh they were facing some issues so basically the issues like one of the vendor from their organization who was connected to their organization has changed their name and as a result of which the email id or you can call it an email domain of each and every employee got changed now they want to update or you can say migrate all those user from the previous email id to the new domain email id okay and the count was pretty significant it was around twenty thousand so it's not possible manually so he was just discussing with me how we can achieve that so in today's video we will try to resolve that issue so for example we will go to the cc user table this is the dot list i miss the t and here we can see what we can see i have changed the email id of few people okay whether hello.com okay so i will i will put a condition over here just to filter out this user so he will be doing based on the organization i will be doing based on the email id so i can go email content employment and run so we want to update the email id we have we want to change the email domain for these four users okay for example let's say technomorph.com okay so for that what we will be doing we will be writing a fixed script so let's quickly create a quick script i'll give it a name as what what name should i give update email domain and probably you will all you may also face this kind of scenarios in your organization because name changing and email domain changing is pretty common practices right so we have created one now what we'll be doing first of all we will glide record and we'll bring out all the users account user glide records okay which we want to change so simply we will variable here we use this but i will just zoom out users equal to the new live record which table we want to go to sales and discord users and now we have to add the query okay in order to get it working so we'll be adding a query what will be the query gr dot and sorry not here user dot and encoded query what is the encoded query so we'll take it from the filter so i will copy this query out from here i will paste it out over here so now i will get fortunately we'll get all the users so i will do gi uses dot query now what we have to do we have to change the email id of of domain not an email id okay domain so basically when i call domain the initial part or the prefix should say the common okay only the domain should get changed after add that you can see so how we can achieve that so we'll use some javascript basic javascript coding so i will do while part gr user dot next now will you take a uh take a usage of regex so i will define our eggs variable r for x equal to new sn c dot drag x this is how you can define the rank x again if you want this should be small drag x and under regex i can give what i want to change so i will give to what is that hello.com okay and now we can simply add dot dot that is all replace all what the old user dot email with new domain we'll give a new domain over here so i will give tech no [Music] right this sounds like fun okay giving my domain to the users and then you can simply go gr dot update gi users product update and so basically what we did we glide record the user okay let's record the user table we have given the encoded query then we defined a regex okay and then we simply replaced it out with the previous user email id with the new one okay whatever will be there and and done so that's all for for the script i will save it out and let's try to execute if it works i will do a run effect script proceed not a background i got an issue on this three what issue not a valid pattern yes actually it's not a valid pattern why because we have to enclose it and then this lashes my bad save and now if i execute hope it will run this type proceed and it's done it took only 0.07 seconds okay and if i go and if i refresh it out till the while still the let's check once again so what we do dtt uses record query user dot next say dot regex here we don't want to it should be am i bad it should be user user because we are updating the gi user right it should be gi user dot emails equal to let's write my bad sometimes mistakes happens now if i run the script proceed it executed let's check we go here we didn't get anything why we didn't get anything because for this users the email id got changed to techno pretty easy right only seven lines of code you don't have to do that much of effort so this is all for today's tutorial hope this script will be useful for my friend okay please like follow subscribe my channel to get the latest updates on videos i'm creating if you have your own queries or use case you can drop me a mail okay i will try to create video on the same also till then stay safe stay happy and have a nice day thank you you

View original source

https://www.youtube.com/watch?v=j46jAG8Y9NA