logo

NJP

Mastering ServiceNow: Different Methods to Set Logged In User as Caller in ServiceNow

Import · Jul 17, 2023 · video

foreign [Music] with the logged in user okay so for our instance I'm currently logged in as oh if you see I'm currently logged as system administrator so what do you want as soon as I log as soon as I open the incident form I should be defaulted on the incident form called the field okay so let's see how we can do it so first of all we will go to the incident dot two okay to see where exactly the we want to fill this information and actually this requirement makes sense also because no one will go to the Instagram form just for form right okay if they are crazy about something then only they will go to the incident form so what we want to do as a part of this use case we want to prevent this column field okay with the logged in user that is system administrator for this use case whenever a user opens this particular form so it's pretty simple to be implemented what you have to do you have to just go to caller configure dictionary and over here will wait for it to get loaded okay so there are tons of tabs over here right okay reference specifically a choice to specifications and so on so you have to go to the default value and under default value okay you have to use use Dynamic defaults and if you go to this reference icon I have already clicked on it okay it's taking some time okay so if you go here we can see there are three already created things okay so incident get caller me and my Med okay so let's go with the me okay why with me I will show you in a second so basically what it's doing you can also create your own Dynamic filter so what how this diagram works filter value works if you go here that I I can write and if you open this out so basically it's also script only what it's doing it's calling this script gs.getuser ID and setting it to the form perfect so you can play around it okay if you want to create more such options you can do it so we have set it out I think it it should work now okay let's see if it's already been said okay it got set to send okay which is the mean one and if I go to incident.go now dot do let's see if it's getting set to the system administrator so now we can see as soon as the form loads it's defaulted to the system administrator so the requirement is completed but let's let's see if we can achieve the same because we have already seen the script right if we can achieve the same using client script so what I will do I will just go to the dictionary again okay call it exteri and over here let's disable this out okay and after disable I can save it out now if we go to S3 and incident form you can see over here if we see the caller is empty now okay so it's not getting filled now let's create a client strip for the same so what you have to do is right click configure go to the client script and we want all load clientscript for the same so I will click new and we'll give it a name as or put it color and we'll make it onload I'll write a simple code over here which is G underscore for dot set value set value of water it's called right so I think it's Corner only and then we can use the um the function which we had okay which we have from from the script itself so we can do the underscore user which gives the call current logged in user details okay so we can do three and let's go to user Dot user ID perfect and we can simply save it out so I will save it out I have to just check whether it's caller or something else so we will go to the history we will open the new record again and I think it's not called so it's caller ID so let's change it out with the caller ID St clients not the new one S3 a sedat and we'll go configure client script populate colon and we have to just change the field name over here this one I'll just change it out to caller ID and save it up so let's see how if it works or not now so we'll go to history again and will open new incident form straight your incident as well and if I see now it's again getting set to the system administrated so we the the expectations completed but one thing here which can be messed up okay so if an instance there is already an existing incident created so if I go to incident dot list so for instance for this particular incident the caller is able to do so it should not update this information outright else it will mess up the things right so if we go over here and if you see but it's changing it out which is not at all the best practice okay because then everything will come if if a user is opening anything out okay it will show that the caller for this incident will be this person okay so how we can avoid this particular thing out so it's pretty easy to manage this also so what we can do whatever your thing is what we can do we can simply go to the client script again and we can add a if condition to check whether it's a new record or existing record so we can go over here and what we can do if G underscore form Dot is new record if it's a new record then only in this particular record this particular logic should apply as it should not and we can simply add this particular thing over there and it's done so so it is done I can simply go save this out and let's open the new form first and see if it's working on that so I'll go history new file a new form got opened and it's getting filled perfectly fine now if I change it to some table tutor okay which is I'll give test once it gets saved okay that means it's the existing record then it should not override that particular information out let's see if it's working like that and now you can see it's not getting changed to the system administrator that means it's working what we put is working as expected so this was a small use case for today's tutorial I hope you liked it out okay and just both the method is now people will be providing question that um what should we do whether we should go with the default setting or we should go to the client strip so whenever there is a configuration present you should always goes with the configuration which is the default setting of the default type okay but in order to showcase the other options also to you right okay I've I've covered it with respect to a client script also I hope you like this video if you liked it out please subscribe to my channel so that you will get notified with upcoming videos till then stay safe stay happy and have a nice day ahead thank you

View original source

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