Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Max Selwyn
ServiceNow Employee
ServiceNow Employee

Creating a record with user input data

If you want to create a record using user input from your form or other component on your page, you can use this guide. In this example, I was taking input from 2 input components in a modal and creating a new incident when the users presses submit. 

 

First create a new transform data resource that will take input and create your new record.

 

  1. Be sure to check the ‘mutates server data’ checkbox. This will allow you to execute it from your client script.
  2. Add properties for each input you will have.

MaxSelwyn_0-1685638326491.png

 

  1. In your script, be sure to check for input values, otherwise the data resource will create records when the page loads or when you view the data resource from UIB.
    1. MaxSelwyn_1-1685638326498.png

       

This example script takes 2 input values, looks up the sys id from the dropdown component selection and creates an incident with a short description and long description with the values selected in each dropdown.

 

  1. In UIB, be sure to set ‘When to evaluate this data resource’ to ‘Only when invoked (explicit)’
    1. MaxSelwyn_2-1685638326499.png

       

 

 

  1. Create a client script to execute your data resource.
  2. You will set the properties in the client script from the execute api.
    1. Example: api.data.your_data_resourece.execute({property: value})
    2. My data resource is named ‘test_submit_1’ in this example.
    3. MaxSelwyn_3-1685638326502.png

       

 

  1. Bind your client script to your button, to submit the record.

 

  1.     MaxSelwyn_4-1685638326503.png

     

Comments
Vishal8
Tera Explorer

This was really helpful, thank you Max for posting it here. 

 

Just wanted to add to Step#2 - please make sure you create ACL to grant access to respective role for the "Data Broker Server Script" created by newly added Transform data resource. 

 

Version history
Last update:
‎06-01-2023 09:56 AM
Updated by:
Contributors