Mobile App Academy: Autofilling inputs form screens using script
good morning everyone and welcome to mobile app Academy this is our live building Series where we show you how to build and configure mobile apps on the now platform my name is David ha and I'm an outbound product manager here at servicenow and I'll be your host for today's session and also want to give you a warm welcome for uh joining us live here today um if you are joining us for the first time welcome uh we have product experts here to provide guidance best practices and answer any questions that come up along the way and we do host these academies every two weeks at 10 A.M Pacific uh in which our recordings will also be posted to YouTube on the servicenow now Community Channel I just want to point out a few resources that we do have available uh although I do notice that some of these screenshots are a bit outdated uh we did go through a new community revamp it's now now has a completely new UI um this is our first initial launch and there's still quite a few things that we are organizing especially for our mobile Community um so just hold on tight with us we will get a lot of these things updated um you might and if you have any feedback with us definitely feel free to share share with us um but you can find our um I I want to point out a few other academies that are available such as our HR Service delivery Academy platform Foundation platform analytics virtual Vision so many others and you can find these Series in their respective Community forums okay uh just to quickly review for today's schedule this will be a very quick 20-minute session we're going to start off with a quick overview uh you know what our goals for today what we're going to implement and how to get started and then we'll jump into the exercise um we're going to cover an enhancement that came into San Diego for input form screens specifically so that you can autofill inputs using a script include um and then we'll open up to some q a uh if you have any questions at the end um one other thing I want to mention is uh if you're looking for more Hands-On training I do recommend that you check out our now learning course that's called Mobile use Baseline functions um and some of our other earlier academies as well um if you're not quite up to speed on today's topic you you can watch our getting started with input form screens Academy which you can find on the community or on YouTube um and these are great resources to get started learning how to use input form screens why they're important and how to build your functions okay so definitely check those out if you haven't already but with that being said let's now jump into our overview for autofilling inputs using input form screens um so input form screens just the reminder that this is what we use to build actions for our users right it's a more streamlined experience for users to enter in their data and we released a new enhancement in San Diego that actually allows us to support a lot new use cases things that we couldn't have been able to do before such as autofilling variables using a script include so you can now do things like Auto populate a field that's based on the logged in user's profile which you can kind of see an example in the screenshot here we can see that the building value was autofilled so that it's one less field for the user to fill out as they're creating their reservation for a conference room right and for today's session we're going to use the field service technician use case as an example we're going to leverage the work order workflow it's an out of the box workflow from the field service mobile app and so as technicians are starting to work on their tasks you know they're required to log in their hours and figure out what parts they need to complete their task and to help with this flow we're going to enhance their existing input form screens so that it autofills the last part that was used on the task so that information is readily available for them as they log in their hours and of course this can be applied to any use case if there's any fields that you feel like it's uh repetitive or there are fields that can be easily autofilled then um it's definitely a great use case to apply to any of your input launch screens okay so um let's go and get started uh just a quick note that we did record this into a short 10 minute implementation video uh to take us through this so let me go and pull that up really quick I'll now start the recording hi everyone I'm Ian Kinnear from the outbound enablement team and in this session I'd like to walk through setting up a scripted parameter form variable this is something you can use to Auto populate an input on your parameter screen based on the execution of a function in a server side script include for this use case I'm going to be leveraging the record time function which comes packaged as part of the field service mobile plugin the function allows a technician to record time spent on a work order task our use case will be display the last part used as part of this task at the top of the record time input screen so that the technician has that information readily available as they log their time so first let's open up our mobile app builder we'll select the field service mobile scope and then click on functions to access our functions we're going to want to find that record time function the one we want is record time parameter screen and from here we can see the layout of our function we've got an action item and an input form screen and together with some inputs and input attributes in order to add a new input we'll click on the record time input form screen scroll down take a look at our inputs here and click new we're going to make an input called last part used we'll get a label you can give it a nice description and we'll select the input type of string and it'll be read only give it an order of one just to put it right at the top of the screen for the autofill variable obviously that's what we're here to do we haven't created it yet so we can't select it here we'll just go ahead and click save now in order to create that autofill variable at the time of the recording of this video in March 2022 we can't create that type of variable yet in mobile app builder but we can just flip over to our platform View and do that so what we'll do is we'll use this overflow menu here to from the record time input form screen and open up in platform so here's that same input form screen just from the platform view we can see all of our inputs here including the one that we just added and we'll click back here under variables and add a new variable which we'll call last part used autofill and this one will have a variable type down here at the bottom of scripted we'll save that and then click into that variable in order to add a variable attribute this variable attribute needs to have the name of script with a capital s and for the value this is where we're going to give it the syntax to get to the script include and function that we're going to use to return back that string so let's take a look at what it looks like here it's standard syntax to invoke a function from a script include it'll be new and then the scope in this case SSN fsmobile Dot scripted autofill so this scripted autofill will be the name of the script to include that we're going to create Open Bracket close bracket dot get last used part that's going to be the function that we'll go ahead and create Open Bracket close bracket so with this we can save this and we'll go ahead now and create that script include so the logic can run so click into our script include list click on new so here to match what we had in our variable attribute it's going to be scripted autofill we can click out of there for it to see it will auto populate the full name with the scope for us and start to create our function our script for us in the script we're going to need that get last part used function in order to create that just click in here give it the function name and we'll create the skeleton of that function now for the next part I won't make you wait for me to type the whole thing we'll just include this in the description of the lab but if we click over here paste this in we can review the logic of what this is the script include function is going to return back so all we're doing here is we're going to open up a new Glide record against the SMS at usage table that's the table that the part usages will be found in we're going to add an encoded query where we're going to pass the current dot sysid for the service or order task so that's the work order task sysid that it's going to be able to grab from the context of the record that our mobile function is tied to and we're going to also filter it for to give us only those part usages that are used on the next line you see this border by this descending that's going to just allow us to grab order them by descending updated orders so that we can grab only our most recent one and on line nine you can see the query being invoked on line 10 so if we return if that query returns a record a row we'll go ahead and retrieve it with next and then here's where we're going to return back our value so this is just going to pull for us the asset on that records display value get display value and we just add it on here to the second part here building out our string the date time that that record was updated on so you can see you can whatever you need to build out in your script you can you know start to see the possibilities and build whatever you need to so this is really all we we need for this function if it doesn't return any record it's just going to return blank so we can go ahead and save this we have one more piece to do before we can leverage this scripted autofill variable in our mobile app which is to go back to our mobile app builder tab and we'll just refresh this View just to make sure that we have that variable available and we'll find our last part used input that created we created earlier scroll down to our autofill variable and now we're going to go ahead and point it add our last part used autofill variable that we created click save at this point looking over at our mobile app we can find a function you should obviously have a function where you've you know you've used a part so we can just tap back and refresh this just to make sure it's updated tap into the task and then we'll access our overflow menu up here to find the record time function tap it and we can see our last part used read-only input here and we've passed in the name of the asset that was used and the date and time when it was used so the technician can see that as they're recording their time thanks very much so that was a very quick quick bite of how you can take advantage of some of these uh scripted autofill variables for your input form screens um we are seeing a lot of questions around input form streams so we wanted to continue doing more App Academy some topics around this um so you might see more future topics um such as um dependent input IDs um how to apply advanced uh reference qualifiers um and so these are other topics that we might explore in the future any questions in the chat before we kind of wrap up for today make sure to subscribe to the new mobile Community Forum register to our mobile app Academy series uh that way you can still continue getting notifications on our latest updates but with that all being said thank you all for joining us today and we hope to see you again in two weeks at our next Academy thanks everyone
https://www.youtube.com/watch?v=ConT_Jxmd7c