The Zurich release has arrived! Interested in new features and functionalities? Click here for more

sachin_namjoshi
Kilo Patron
Kilo Patron

Introduction:

 

NOW Assist for creator  OOB has great skills to to generate servicenow development objects ( e.g client scripts, flows, Playbook generation). These plugins should be recommended and implemented for servicenow customers as a first preference.

 

Also, There are so many LLM models ( e.g Chatgpt,  Claude) already which can generate servicenow code with effective prompt engineering.

I have explored and integrated cursor IDE with Claude LLM  and servicenow instance for a bidirectional sync so that objects created, updated in cursor IDE can be synched to servicenow instances and also same object can be synched back to cursor.

 

Purpose:

 

This article is created to document steps to integrate servicenow instance and cursor for a bidirectional sync.

 

Solution:

 


πŸ”„ Bi-Directional Sync Setup (Cursor ↔ ServiceNow)


1. Link ServiceNow App to GitHub Repo

  • Login to servicenow instance with admin role and navigate to  Studio β†’ Source Control > Link to Source Control

  • Connect to your GitHub (or GitLab, Azure Repos) repository.

  • With a successful connection, all artifacts (e.g Script Includes, Business Rules, Client Scripts) are stored as XML/JSON in Git.

  • This is pretty standard config step which most of servicenow developers used to link source control for their custom apps.

βœ… This is the "single source of truth" that both ServiceNow and Cursor will talk to.


2. Clone Repo in Cursor

git clone https://github.com/org/servicenow-app.git
cd servicenow-app
  • Open this repo in Cursor IDE.

  • Cursor now has full access to all ServiceNow files (like sys_script_include_xxxx.xml).


3. From Cursor β†’ ServiceNow

  1. In Cursor, ask AI chat with your required prompt like below :

     

    "Create a new Script Include UserUtils with a method getManager(userId). This method should return user's manager and userid will be passed as function param"

  2. Cursor will generate an XML file like:

    <record_update table="sys_script_include" sys_id="auto_sys_id_here">
      <sys_script_include action="INSERT_OR_UPDATE">
        <name>UserUtils</name>
        <access>public</access>
        <client_callable>false</client_callable>
        <script><![CDATA[
          var UserUtils = Class.create();
          UserUtils.prototype = {
            initialize: function() {},
            
            getManager: function(userId) {
              var user = new GlideRecord('sys_user');
              if (user.get(userId)) {
                return user.manager;
              }
              return null;
            },
            
            type: 'UserUtils'
          };
        ]]></script>
      </sys_script_include>
    </record_update>
    
  3. Cursor saves β†’ commits β†’ pushes to Git:

    git add .
    git commit -m "Add UserUtils script include"
    git push origin main
    
  4. In ServiceNow Studio β†’ Source Control > Pull

    • The new Script Include now exists inside ServiceNow. πŸŽ‰


4. Workflow: From ServiceNow β†’ Cursor

  1. Suppose a developer edits UserUtils Script Include directly in ServiceNow.

  2. In Studio β†’ Source Control > Commit Changes

    • This pushes the new XML to GitHub.

  3. In Cursor, run:

    git pull origin main
    
    • Cursor now sees the updated script.


5. Automating Sync

Prerequisites

  • ServiceNow app already linked to Source Control (GitHub repo).

  • Personal Access Token for GitHub.

  • ServiceNow DevOps integration (or REST API credentials with admin + source_control roles).

Add GitHub Action Workflow

Create a file in your repo:

.github/workflows/snc-sync.yml

 

name: ServiceNow Sync

on:
  push:
    branches:
      - main
  schedule:
    - cron: "*/15 * * * *"  # every 15 mins check SN ↔ Git sync

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      # Step 1: Push changes from GitHub β†’ ServiceNow
      - name: Push GitHub changes to ServiceNow
        run: |
          curl -X POST \
            "https://<your-instance>.service-now.com/api/sn_source_control/push" \
            -u ${{ secrets.SNC_USER }}:${{ secrets.SNC_PASS }} \
            -H "Content-Type: application/json" \
            -d '{"applicationName": "<your-app-scope>"}'

      # Step 2: Pull latest from ServiceNow β†’ GitHub
      - name: Pull ServiceNow changes into GitHub
        run: |
          curl -X POST \
            "https://<your-instance>.service-now.com/api/sn_source_control/pull" \
            -u ${{ secrets.SNC_USER }}:${{ secrets.SNC_PASS }} \
            -H "Content-Type: application/json" \
            -d '{"applicationName": "<your-app-scope>"}'

 

Store Secrets

In your GitHub repo β†’ Settings > Secrets and Variables > Actions

Add:

  • SNC_USER β†’ ServiceNow admin user

  • SNC_PASS β†’ password (or OAuth token if using DevOps app)

Workflow Behavior

  • Every push to main β†’ auto-pushes into ServiceNow.

  • Every 15 minutes β†’ auto-pulls ServiceNow β†’ commits back into GitHub.

  • Cursor just needs to pull latest GitHub changes (git pull), and it’s synced.

 

Cursor Setup

In Cursor, you can also add a post-save hook:

 

 
git add . git commit -m "Cursor update" git push origin main

 

So whenever you accept AI changes β†’ they go straight to GitHub β†’ GitHub Action syncs them into SN.

This way, both Cursor and ServiceNow are always in sync with GitHub in the middle.

 

End Result

  • Edit in Cursor β†’ auto β†’ GitHub β†’ ServiceNow.

  • Edit in ServiceNow β†’ auto β†’ GitHub β†’ Cursor (on next pull).

  • No manual clicking needed in Studio.


6. Limitations / Gotchas

  • My experience was better with client script,script includes and business rules for a scoped app development.

  • Flows (Flow Designer JSON) are harder to hand-edit β€” best edited in ServiceNow, but still sync via Git.You can still create a them using prompts in Cursor IDE.

  • You must always pull latest before editing in Cursor to avoid merge conflicts.

Conclusion:

 

You will be able to follow same solution for most of your preferred LLM models. Happy Exploring!.


βœ… Recommended Setup

  • GitHub repo = single source of truth.

  • Cursor = your local editing + AI generation environment.

  • ServiceNow Studio = your in-instance editing environment.

  • Both sides push/pull to GitHub β†’ automatic sync.


 

Version history
Last update:
3 weeks ago
Updated by:
Contributors