Reference field is a key functionality for many ServiceNow applications. Especially when it comes to custom web apps and Service Portal.
This implementation is based on react-select and react-select-async-paginate libraries, so you can use all of their options and features in your ServiceNow applications.
The key idea for this reference field (record picker) implementation is to show how you can utilize React components for ServiceNow applications and create complex functionality with a few lines of code.
- Clone this repository
git clone https://github.com/elinsoftware/sn-react-record-picker.git
- Install dependencies
npm install
- Set up proxy to handle requests to your ServiceNow instance
In package.json add:
"proxy": "https://<instance-name>.service-now.com"
- Add your ServiceNow instance account and password by creating an
.env
file
In .env add:
REACT_APP_USER=<your-username>
REACT_APP_PASSWORD=<your-password>
- Run React
npm start
You're all set to run React app locally 🙂
- Build the application package
npm run build
- For each .js and .css file from build/static folder create a Style Sheet record in ServiceNow, copy the corresponding code.
- Create UI page, set
Direct = True
. Copy HTML code from /build/index.html. - Replace inline javascript code in HTML with a reference to the
runtime~main
code from the corresponding Style Sheet. The reference link should look like[style_sheet_sys_id].cssdbx
- Replace all other links with references to the corresponding Style Sheets.
Your updated UI page should look like this:
You just deployed a React application to ServiceNow.
Open the UI page in a browser to see how the application works.