$rootScope not defined in UI script

Ace009
Tera Contributor

So I have a UI script that sets a variable on a Record Producer. The value of that variable needs to be broadcasted to another widget. However, Im getting a "$rootScope is not defined" error. I had a similar error with g_form but added a few lines per this post:

https://www.servicenow.com/community/developer-forum/unable-to-access-g-form-in-widget-code/m-p/1847...

 

So Im thinking I need to do the same for $rootScope.$broadcast but I dont know what to import.

 

I do see some OOTB UI Scripts use $rootScope.$broadcast but Im not sure what to extract from them.

 

Thoughts?

3 REPLIES 3

jcmings
Mega Sage

Can you provide some more information:

  1. What variable does the UI script set on the record producer (and how)?
  2. Is the widget that receives the broadcast located on the same record producer?
  3. Why does the widget that receives the broadcast need the variable value?

I think there is another way to achieve what you're trying to do, with less complexity. 

Ace009
Tera Contributor

Hello!

1) It's just a custom variable that stores a response from another page. The UI script handles the user interaction, then calls g_form.setValue() to update this variable.

2) The widget receiving the broadcast is on the same Page, not in the record producer. Sorry, should have made it clear this is on the Portal and a page has the OOTB SC Catalog Item widget.

3) To display something per requirements.

 

My issue is that Im getting an error of "$rootScope is not defined" in my UI script. I had this same issue with g_form until I had to add a couple lines which seems to import it.

 

Modifying my original post for clarity.

I've actually never used a UI Script before. An alternative would be to use GlideAjax and a client script and then broadcast from there. I would also recommend asking ChatGPT for an idea; it's typically very good at filling in the blanks.