Quick Functions/Script Include Intro

For more information on this, definitely check out Eric Riemer’s CreatorCon Session from Knowledge 2021 and the accompanying ServiceNow Developer Share Item with more examples!

-

We are using the PDF in this post as an example to explain how to call a Script Include from a script.

On Page 6 you will see the Assignment Rule Script. Take a quick look at that and then note:

  • Step 1 is building the groupId variable.

  • Step 2 is building the userArray variable.

  • Step 3 is calling the script include using:

var matchingRuleProcessor = new global.MatchingRuleProcessor()

Which is then actually being ran by using:

var candidates = matchingRuleProcessor.processRuleRecord()

The MatchingRuleProcessor() is the name of the script include and then the .processRuleRecord is the function that’s being called inside the script include.

Everything inside the parentheses of the

matchingRuleProcessor.processRuleRecord(current, matchingGR, userLimit, userArray);

line are considered Parameters. They are pieces of data that the function will then leverage to work. These names will likely not match what the function itself uses as variables, so what’s important is the order that they are in when comma separated. There are often optional parameters in functions, so you may not always need to supply the same number of parameters as the function can accept.

This is what the Script Include’s Function could look like:

process : function(task, users, taskFieldValues, args){

}

You can see that it’s expecting four parameters, which will then be used inside of the function to do things and such. Those are going to have the data of the variables you used in the parentheses above, but under new names. You can tell what each of those parameters is used for by looking at the script include and function’s code to see where it’s used.

Since I can’t find it in the script include, the last parameter is likely something to do with the JS Arguments found on here. Let me know if you have any better ideas down below.

Maria Gabriela Waechter

She/Her || Senior Outbound Product Manager @ ServiceNow || 2022, 2021 ServiceNow Developer MVP

Maria Gabriela is passionate about making ServiceNow resources and opportunities accessible to everyone regardless of income, identity, nationality, upbringing, or environment. As a proud member of the LGBTQ+ community, a Venezuelan-American immigrant, and a woman with disabilities, Maria Gabriela strives to break boundaries and highlight the contributions of traditionally marginalized groups.

https://mgopw.dev
Previous
Previous

UIB: Transforming data for Related Content Component

Next
Next

Adding the variable editor to custom tables that are NOT task based