Pre-filled fields - Did You Know
foreign with another Did You Know video this time I've got not one but two ways you can quickly display a form with pre-populated fields even Dynamic values and no I'm not talking about dictionary default values before I go on just a quick reminder to click like on this video if you find it helpful and subscribe to our YouTube channel to make sure you don't miss anything good okay back to our main topic to start have you ever noticed when you create a new record from a related list that the link back to the parent record is pre-populated pretty nice right this is made possible because the same query that makes the related list is used to pre-populate the field let's take a look at an example when we look at this problem record we can see it as several incidents related to it that's because the incident table has a reference field to the problem table and the value for that field on all these records is this problem to make this list the system is simply checking which incidents have prb11 in the problem field we can see this at the top of the related list right here and when we right click on that query and select open new window we get a new browser tab with the same list with the same query and notice something else when we click new the problem field on the incident already knows to link to prb 11. that's because of a URL parameter called cisparm underscore query did you know you can take advantage of the cisparm query parameter to not only filter records you can use it to also pre-populate fields if we look closely at the URL we can see sysparm query equals problem ID percent 3D and assist ID I know not the easiest to read but it says populate the problem ID field with the sysidia prb 11. the percent 3D is simply an encoded version of the equal sign so it doesn't get confused as a URL parameter it's that same cisparm query on the URL that tells the system What fields and values to populate on the new record that's how the problem field gets populated cisparm query does two things for lists it filters for a form it populates fields let's try a simple example of Our Own back on our incident list let's create a simple query where channel is Walking we get our list as expected from the filter operation and when we click new the new record automatically has Channel filled in why is this useful well how about this let's say we want to make a new module in our navigation menu so when somebody walks up to our desk with an incident we click one thing and the form is already open with the channel set to walk in to do that we'll right click on the breadcrumb and copy the URL now we'll create a new module and yes there are lots of ways to do this for this example we'll edit the incident app menu go down to the modules related list and click new in the new module form notice how the application menu has incident already populated now we know how that happens cisparm query let's finish filling in the form we'll call our new module new wakia order 1000 and in the link type section we'll pick URL from arguments then paste in our URL from before we still need to make a few adjustments to the URL first we'll remove the instance name up through.com so that this URL works on other instances like our Dev test in prod next we get rid of underscore list so the system opens a form and not a list and after the question mark we'll tell the system to create a new record by putting in sysid equals -1 and an ampersand to separate the URL parameters sysid from sysparm query next we remove the cisparm view parameter altogether and finally submit Let's test it out by going to the all menu type walk in the filter and there's our new module and when we click it we get a new record with the channel pre-populated now if we want to pre-populate more fields we can add those to CIS Prime query in the same way by building the filter and replacing the sysparm query in our module here's one that pre-populates the assign to field as a dynamic value of me cisparm query is a great way to pre-populate Strings numbers Choice Fields reference fields and several others you can even hack a read-only field to take on a value in a new record however it doesn't do well on fields like calculated or lookup Fields like priority the initial value may look fine until the system does a calculation or lookup and replaces our value you'll find it also doesn't do well on fields like state in the task tables that have logic driving the default value and it won't work on fields that don't use the is operator like list and date fields if the sysparm query doesn't have an equals it's noted with the percent 3D then the form won't be able to assign a value consider using sysperm query in modules UI actions interceptors and other places you can navigate to a record with a URL now as a bonus if you find your setting more than say three or four default values you may want to consider predefining the values in a template and using cisparm under template to manage the field value pairs easier let's convert our previous example to a template first we'll start by navigating to all system definition templates and creating a new template we'll give it a name select the incident table and make it Global so everyone can use it then we'll give it a short description now when we set Fields we'll set the channel to walk in and the dynamic assigned to is entered as JavaScript colon gs.getuserid this is taken right from the dynamic filter option now I won't get into all the details of the JavaScript colon options here but it offers some flexible ways to do things like dates call script includes and more documentation for dynamic filter options is available on the docsite and I'll include a link in the description for this video just for fun let's add an additional comment to tell this template apart from our previous example we'll then save the record and copy the name next we'll modify the argument field in our walk-in module replacing CIS parm under query with sysparm underscore template equals and the name of our template Let's test it out there's the new record with the values we set in the template including the additional comment even better if we need to modify any of the field value pairs we don't need to change the module like we would with sysparm query we can quickly modify the template anytime we need and as long as the template name stays the same our module continues to work with the new values a one word of caution avoid characters in your template name that could cause conflict with the URL like question mark Ampersand and equals there you go a couple of different ways to pre-populate fields on a form quickly using cisparm query and sysparm template I hope you find new and creative ways to use them in your system don't forget if you've got a tip or a trick that you want to share in a Blog video or whatever be sure to use the hashtag servicenowdyk to be part of the community I've seen some great stuff already and I look forward to more thanks for watching thank you
https://www.youtube.com/watch?v=spWJe-icus0