Has anyone experience with scopes when creating custom components for the ui builder?

Barrilito van D
Kilo Guru

Hi developer friends 🙂

I have a question regarding the scope when creating custom components to use in the UI builder.

As far as I understand from the documentation each project gets its own scope. As most examples online have one component in one project it first felt like each component gets its own scope, but it is project based I realise now.

When deploying the project to your instance you see the scope being created and that works fine. 

However, I now wonder, if for each project it creates a new scope, then the instance will get full with new scopes created by custom components. I can understand the advantages that perhaps this was choosen so that each project can be controlled well, giving it certain access and protect the data. But on the other hand I am struggling with how many components to put in a project and what to consider a project. I think lots of things you want to create you would want to consider a new project, which leads to many new scopes. I guess that is not desireable for the servicenow system to suddenly see 20 new scopes being created.

Has anyone experience with this? What do you consider a project? Do you create scopes on the fly and do you see disadvantages in that?

I would love to hear your experiences, thoughts or perhaps reasons behind this approach as it feels for me that I would have expected or liked it more if I could set one scope and always deploy my components to that scope so that it looks clean and tidy.

Thanks in advance!

3 REPLIES 3

DrewW
Mega Sage
Mega Sage

In less it has changed since I built my two components over a year ago you can use the same scope for all of your components.  At least thats what I did.

 

Thank you Drew for your reply.

I guess you then mean that you have one project that was one scope and that all components you made you kept on reusing that project.

So I created one project.  Then under that project I created a folder for each component and ran all of the commands to create the component in that subfolder.  Then I just run the debug command for the one I want to work on.  In the now-ui.json I put in the scope name I wanted to use.

But looking at the code one I added to an existing application but setting the scope to the same as the applications scope and the other I put in its own scope because it was generic.