Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Widget dependencies as js modules

Nisar2
Mega Guru

Hi experts,

 

I've a need to use the following script inside my widget

 

<script type="text/babel" data-presets="react,stage-3">
   const { LocationMap } = window.geoJsLib;

    const SampleMap = () => {
      return (
        <LocationMap
          onSubmit={(location) => {
            alert(`${location.latitude}, ${location.longitude}`);
          }}
        />
      );
    };

    const root = ReactDOM.createRoot(document.getElementById('root'));
    root.render(
      <SampleMap />
    );
  </script>

 

 

How would I go about including it in the widget? I tried creating a UI script and then adding that as a dependency in the widget, but then it throws the following error:

 

Uncaught SyntaxError: expected expression, got '<'

 

which suggests that it's not able to understand JSX (I've already included js files related to React as dependencies) but I'm thinking the <script type="text/babel"> part is where ServiceNow is having a hard time interpreting.

 

Is there a way to get this working?

 

script_5 is the UI script

Nisar2_0-1697615864957.png

 

UI script usage

Nisar2_1-1697615910689.png

 

 

Widget HTML

Nisar2_2-1697615943790.png

 

Client controller and Server scripts are empty (as in no lines of code)

2 REPLIES 2

Nisar2
Mega Guru

Tagging some experts for better reach as I feel not many would be experiencing this problem

 

@Ankur Bawiskar @Dr Atul G- LNG @Rahul Priyadars @AnveshKumar M @Sandeep Rajput @Peter Bodelier 

Nisar2
Mega Guru

Any help please?