{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":37887,"path":"order-management/scripting.md","title":"Create scripts","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create scripts\n\nLearn how to create advanced functions using the scripting interface.\n\nSome use cases require an advanced condition or action. Other times, the administrator may prefer script versus leveraging simple rules. For these occasions, CPQ offers the ability to write scripts in key areas.\n\nScripting is available in rule actions and conditions, behind the Advanced menu choice or toggle.\n\n\\[Omitted image \"cpq-scripting-advanced.png\"\\] Alt text: Rule\n\nWhen you click **Create Advanced Function**, the script editor opens, including the tools you need to write a script.\n\nWhen the script editor first opens, it provides the expected return format of the script.\n\n-   Advanced conditions return true or false.\n-   Advanced hiding rules return a text string.\n-   Advanced determination rules return the type of the field that they are setting.\n    -   A determination rule that sets a number returns a number.\n    -   A determination rule that sets a multi-select picklist returns an array.\n-   Advanced inclusion and exclusion rules return an array.\n-   Product rules return ProductList.\n\nFor more details and a script sample, review the \"Advanced product actions\" section of [Rules](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/rules_101.md).\n\nThe **? Help** button opens a menu of available functions. Each entry includes a description of the function, the parameters it accepts, its output, and an example that can be inserted at the current location of the cursor in the script.\n\n\\[Omitted image \"cpq-scripting-available-functions.png\"\\] Alt text: Script\n\nAs you type in the script editor, suggestions are provided, including functions, configurable field variable names, and local variables. Using this feature helps eliminate mismatched variable names and typing errors. In the screenshot below, typing `Ma` gives the user two available functions \\(Map and Math\\) and a list of all matching fields. Additional inputs narrow the list of matching options.\n\n\\[Omitted image \"cpq-scripting-typeahead.png\"\\] Alt text: Map structure\n\nAt the bottom of the scripting interface, the debugger lets you test your script by defining values for the variables \\(fields\\) that it references. Debugger input is provided in JSON format. For your convenience, review field-specific formats in the fields information help \\(arrow\\).\n\n\\[Omitted image \"cpq-scripting-debugger.png\"\\] Alt text: Help screen\n\nIt can be helpful to save your debugger inputs as comments in your script for easy pasting into the debugger when you need to test the script.\n\nCalls to `console.log()` in the script are returned in the debugger output.\n\nAlso see the following sample scripts:\n\n-   [Sample Message Script - Array and Map Function](https://docs.google.com/document/d/1SqDGH6Y6UKV-0kGhzuqfGyII1dI2CezzQifEzulNlfY/edit)\n-   [Sample Number Field Determination](https://docs.google.com/document/d/1HvC6jybMhpgEgvsPnvlt7kwmiXKTYtVjJqmL3iANiHU/edit)\n-   [Sample Product Rule Scripts](https://docs.google.com/document/d/1bSJ_kMcJmHnlH6C67U6tatpxha-EBzyp1IJX5XQ3FYA/edit)\n-   [Sample Product Rule Script With For Loop](https://docs.google.com/document/d/1ICHHJVT3ITlbozUIqpMZTEkUEZgEBbwMoiNWAK6JsO8/edit)\n-   [Sample Text Field Determination](https://docs.google.com/document/d/1Vgkixyoh4m51UYh1nC60gOyfNZ9-VSZKlU8ojJQuhF0/edit)\n\n**Related topics**  \n\n\n[CPQ scripting language reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown)\n\n[Sample scripts](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/cpq-sample-scripts.md)\n\n[Using comments and the console to debug scripts](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/rules-enrichments-comments-and-console_log.md)\n\n[Scripting: Checking for first and subsequent configurations](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/enrichments_on_configurer_and_reconfigure_behavior.md)\n\n[Scripting: How to populate set values](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/enrichments-on-configure-reconfigure-scripts-how-to-populate-set-values.md)\n\n"}}