#10 Custom Action in Flow Designer | Create Custom Action in ServiceNow | Flow Designer Training
[Music] thank you hello everyone welcome to SAS with servicenow this is part of flow designer training in this video you will learn about custom actions in flow in servicenow servicenow provides a lot of out-of-the-box actions which you can use in your flow like create record update record however it also gives a feature to create actions directly by developers and that's called custom actions flow provides an action designer which is used to create custom actions you can create scripted actions that appear codeless when added to a flow you can also build Integrations using integration Hub with action designer for an integration not available out of the box now custom action also has some components and those components are inputs action steps outputs while creating a custom action you will use these different components so let's see in servicenow instance how you can create a custom action from scratch in order to fulfill a requirement which is not available out of the box in servicenow this is my personal developer instance now I will show you that how you can create a custom action in this instance so for that I need to open Flow designer first so I will go to all I have this flow and then I will click on this flow designer flow designer will be opened in new tab as you know you always get this new button when you click on this new button you can create a flow subflow action data stream now we are talking about action we already created a lot of flow we already used a lot of actions out of the box actions but in this time I will be creating custom action so I will click on action and now what kind of action we should create now servicenow if I talk about inflow designer it does not provide any event creation so for example if I need to generate an event so let's let's check the example let's say I open a flow I will maybe create this flow because anyhow to run the demo basically to run the action I need to create a flow so let's create this so demo dot custom dot action I will join by System user this is that is totally fine scope is global I will just submit this for now now uh it is getting processed and then it will show me that this action this flow is created we can see it's still processing I don't want this tour I will skip tour here I can add a trigger but I will do it later but I will just show you ah let us say I need to send an email so in order to send email servicenow definitely provides out of the box action which is send email now this email is you can you just need to put the data input and you can just send it but if I talk about even trigger that means the emails which you want to trigger from an event for that because that's how you want to use uh in in Native development as well not just with flow because no notification email notification is a feature of servicenow where you can select whether record is updated created or you want that as per the event that you can do that so what we want to do we want to do the similar thing because we want to generate an event and this event is will not be used just for email it can be used anywhere you want where you just want to trigger an event to process something so let's see how you can create an event now for that service now has a feature which is called it's it's an API which is called generate event GS dot generate event so before I talk about this let's do go to the scripting view first and see in the in server side code that what exactly that GS dot even queue is because it's for basically for maybe uh some some new users or new viewers who are not aware of event queue so I will talk about that first so um I can open any maybe um I will just do business rule I'm sure it should have uh some even Q because that's a server side script we have uh if I open this um and I have this script maybe I will I will just search here script contains event queue if I click on run see we do have so if I click on this it should have that script which has that API so I go to Advanced and under Advanced you will see that script so you can see we have this GS dot event queue then we have the name of the event and then basically you have to add the current record and then you have to provide some parameters so if I just show you that what kind of parameters you need so you just put event queue if I press tab you will see it needs a name that is the name of the event then you have a record it means the current one and then you have you can provide parameters or if you want to provide a queue which is the last parameter you can provide that as well if you will not provide any queue it will use the default event queue now let's try to use this in your flow because flow does not provide any feature where we can generate an event it you can send an email but not on the basis of event or maybe you want to do something else on the basis of any event so let's do that so if I go to flow and here I have to start with creating a custom action so I will click on this new button again click on action and now here I will just mention maybe demo dot I can put any name I want custom or I will just put demo dot event Q or generate dot event Q and I can I have this application Global accessible from all Scopes you can give category so for any custom action you can give category that what kind of category it is uh it's basically taking a little bit time it's our personal developer instance um email uh I think that's fine I will not give any category for now you want to give any annotations to basically upper right action titled maybe if people want to read so this this action this action generates and event registered registered in event registry event registry uh falling inputs are needed so what do you want so basically you need Maybe name that is I will just put event name and then I will put current record uh glider card basically I can put Glide record I will put basically parameter if I go here GS dot event Q so you have glider card panel one pattern two and so parameter one parameter two and then here I can give name so these are different inputs uh I can give so this action generates an even registered and event registry okay so I will just click on submit so first it is just creating uh this particular custom action but now I need to provide components and if you remember we did we had different components of custom action inputs action step and then you have outputs this is error evaluation if you will get any error that what kind of evaluation you want but here is the step which is action steps so I will start with input because for event Q you definitely need to provide these different inputs and those inputs are I will start you can provide the variable name so here I will put events name it can be string I can create next one then I will provide Glide record uh I can make this maybe uh reference yes we can give it as a reference if we all Let It Be suicide I think it's it's a string only it is string only so if I just do event press tab it's record Glide record but you can see we have this current so I can add it I think here you need to add that table so maybe it is asking me for selecting any I don't want to select any particular table because it's it's for the record uh so for that I can maybe put for now let's make it string only I will keep it straight I will not change it uh let's see what happens let's see if we will get any error so here I will just do a blade record okay and here I will just do parameter parameter one Let It Be string and here I will just do para meter two and then I have again one more which is Q name Q name and this is definitely not mandatory this is mandatory for sure I will make this one as mandatory uh parameters I will just leave it's up to us whether we want to give that parameters or not so I will just uh save this for now so we have given these five inputs uh output I don't think we need any output because it is just triggering of an event so I don't think we need that so for now I will just click on this action basically if I click on this yeah so you can search for the step now step would be basically I want to write a script so if I go to script I have to write a script where is script search for script yet I do have so I will select this and now here I can just select my code I can write a code here so I will come here and now I have to write the same code GS Dot event Q now here it is asking me to provide those different parameters so I definitely need to provide how so that will be inputs inputs dot so you remember we had all those different variables and now you can create the variable here so we will start with so you have to provide input variables as well and you have to map them with the inputs how so here we have first name uh value I can pull it from here then I will create another V variable which is record and here I can put Glide record um here I can just parameter one and this will be parameter one then again I will just do parameter two and I will just mention um basically two and then one more which is q and that will be Q name that's it and here what I can do I can start with input dots queue name which is the first parameter then I have uh inputs Dot inputs Dot record comma inputs Dot parameter parameter one comma inputs dot Pera to comma and here we have this Q name which is inputs Dot eoe so that's our Q name and I will just put semi colon that's it and you have to remember you definitely need to have a record in event registry then only you can trigger this event so I don't need any output so I will just save this and let's see if I get any error if it works or not you will see that so this is created this will trigger this uh I will just click on publish so you can see the main thing is if you remember the uh the point we mentioned about action designer that you can create custom action maybe with a big big code but then you can reuse and that's the powerful feature servicenow provides via flow designer that you want to use a specific thing which you want to reuse every time it's not about just this kind of event anything which you think that multiple developers can use same feature where you need to write maybe multiple lines of code you just code it once and then use it reuse it wherever you want so in this case um I'll just keep this as is required runtime I don't need any output variable because it just needs to trigger this event that's it it says if this step fails stop the action and go to error evaluation don't stop the action go to Next Step okay I'm not I'm not touching this right now let me go to here here I will just add basically I will close this and I will reopen this so that I can select that action I will just do updated here I have this demo custom action I will just add a trigger and we will try to use this with the incident maybe I will just select incident record so if incident is created and if I use this I will just select incident If instead of any incident is created and what I should do it should trigger that event so oh I can just search that it is basically we got generate generate generate yes you'll always find in global so default as as for the application scope you select so here we have demo dot generate event queue and then you can see these two are mandatory so for from where I will get this so event name so I can provide any even name I want I have to create it as well so let's say I will just mention uh demo Dot our demo incident dot created this is the name of the event this is looking for basically so I can put this uh parameter I will get I can maybe um maybe I will get some data so from incident record maybe I will get um assignment group assignment group name where is Simon group name assignment group name in parameter one in parameter two I would have maybe state and that is where is state status right here I will select state I will not select Q name I will just make it as done and I will click on Save we will see whether this event is getting generated or not so now you can see I don't have to write that code again that GS dot event queue but let's see how it works I will click on activate I need to now create an incident and we will see whether we are getting the right output or not basically event is even should be generated so what we will do before we start that I need to go to basically or even registry table so I will go to [Music] event registry yep so we have this event registry I will click on leave because I only want to change the code I have all these uh basically event Registries so I will click on okay these are all events three so I'll click on new and I will basically create this one I will select the table incident um fired by it's it will be fired by so you can mention that how exactly it will be fired it will be fired by this flow um you can just mention flow uh if I talk about before flow designer you used to mention BR and you used to generate the event uh Q I'm I'm not putting anything here um caller access description nothing and I will just click on Save and you are done let's try to create an incident and let's see if we are able to generate the event or not so I will go to incident and here I will click on create new because I want to create a new incident because I want to generate an event here I can select any caller I want so maybe form is getting loaded I will just select Apple tutor Maybe uh demo for custom action I will definitely provide a Simon group maybe I will select database [Music] and I will just save it when I will save this it should definitely trigger that event as per the flow so let's see so we have saved it it's getting saved so you can see it's saved but now we will go to our flow and I will check the execution so if I click on execution yep you can see this got completed so let's see the logs that's the most important thing uh flow reports not available check system property level open context record that's fine I still want to check this uh I want to see all executions let's go here to executions and see if I can check the logs created yep we got this one let me open this um Tech system property flow reporting level okay open the context so reporting off okay so reporting is off if I go to reporting level let's let's go to this property if I go to this property oh I'm doing sis thumb access properties not system okay let's search that property oh it's off so I can make it on uh it's all flow only flows action I think it's better to maybe make it on so I will turn it on it's on and if I reload it I think I will I will not be able to get that maybe let me check if I will get it because we have already uh reports okay that's fine it is not available for this one I will just close it and I will create another incident so let's try again incident dot do because as of now I have made it on and I will select any another incident Apple tutor demo for custom action I will select the assignment group as database and just click on Save if I click on save it should definitely trigger this time again I will refresh it yeah you can see it again says complete if I click on this I hope yeah see so we got this first step completed it got triggered successfully but the important part is this one we got this action and it says completed let's see so we got this it says I got the Glide record as well and it completed successfully let's see uh if I have the right data I can see it maybe in the event logs if I go to event and if I go to event logs yep we have it see and if I open this you will see the magic so it basically even if you didn't have flow designer in the logs but even what was definitely generated you can see two different events this was the latest one um I think this one and if I open this you will see same details absolutely see so we have the name of the event it says processed parameter one database which is the assignment group name parameter 2 which is the state of state of that incident and it got processed it is the instance basically it is the Glide record I think yes it is the current record it is that instance that's how you can generate event that means I just stick to hat because I'm sure even if you do daily development you must be creating you must be generating these kind of events via business rules but now if you will just create this custom action you don't need to code that again and again you can just create a custom action once reuse multiple times and that's not only just one for one developer any developer can use it in flow designer so that's how you can create custom action in flow designer and by this it's just an example just a demo but you can create any flow any flow action any custom action as per your business requirement you just need to think about it from architecture perspective that which action will be really useful which you use every day maybe maybe you need to find out with a new team that which particular work they keep on using uh maybe everyday developments in that case you can create it and just create the custom action used in the flow so I hope you like this video thank you have a great day
https://www.youtube.com/watch?v=HQZCUQQd0ro