CWM - questions on creating a space automatically

mah1
Kilo Sage

Yokohama

 

Would like to know if the following is possible...

 

When a new IT person is added, we want to automatically create a new space named 'Welcome to IT!' in CWM for that person then apply several templates to that space. These templates would add various documents and tasks to the Welcome to IT! space for the new IT person which will familiarize them with standard operating procedures and requirements.

 

Is it possible to do this using a script or flow?  What tables are involved? Where are spaces stored for a user? I looked at the sn_cwm_space table but that doesn't seem to list spaces created by users.

 

Thank you!

1 ACCEPTED SOLUTION

Sunil B N
ServiceNow Employee
ServiceNow Employee

Hi Michele,


This is great use case for whole Space to be saved as template. This is in our future roadmap.

Nevertheless, Currently this is feasible with Flows and scripting.
Steps:
1. Creation of Board template for tasks

2. Creation of Doc template with multiple pages for on boarding of the user.

3. Creation of Space. This step also automatically creates permission(sn_cwm_persmission) for the user to access that table

4. Creation of new Board using the Board template from step 1

5. Creation of new Doc using the Doc template from step 2.

Technical details:
a. Use new space as CWM user and create required Board and Doc template. Keep track of sys_ids. You can take a look in the table `
sn_cwm_template`
b. Create a new flow to trigger when new `sys_user` under `IT` Department is created then create a new Space.
table: sn_cwm_space.
c. Using `
sn_cwm.CWMTemplateService` script API, use `createFromTemplate: function(templateId, type, sourceId, sourceType, additionalParams)`  

templateId : sysId of template from Step a.
type: "doc"/"board"
sourceId:  space sys id from previous Step b.
sourceType: "space"
additionalParams: json as below
{
sourceTable: 'sn_cwm_template',
label: 'Doc or Board name',
triggerPoint: 'cwm_create_button', //required for doc 
docId: '-1', //required for doc 
}

This will create records mainly sn_cwm_board, sn_cwm_menu_item, sn_cwm_doc, sn_cwm_doc_page, sn_cwm_doc_m2m.


Alternatively you can include in the personal space we create: take a look at 

sn_cwm.CWMNavigationAPI._getOrBuildPersonalSpaceGr().


Disclaimer: The APIs used may be subjected to change in the future releases.

Hopefully this would help to get started.

Please let us know if you have any further questions.



 

View solution in original post

15 REPLIES 15

Sunil B N
ServiceNow Employee
ServiceNow Employee

Hi Michele

 

Great to hear that you were able to achieve the use case.

1. Is it possible to create a folder with documents as a template and add that to a space? 
Yes, it is possible. Make use of sn_cwm.CWMFolderUtil script include.

Hi Sunil,

 

Thank you so much for the information. I will try to experiment with this sometime this week and will let you know how it goes.

 

Thank you again,

Michele

Hi Sunil,

 

I am getting an error when I call (new sn_cwm.CWMFolderUtil()).createFolder('Intro',spaceId,'space');  where spaceID is the sys_id of the space.

 

Evaluator.evaluateString() problem: java.lang.SecurityException: Illegal access to package_private script include CWMFolderUtil: caller not in scope sn_cwm: com.glide.script.RhinoEnvironment.checkScriptableAccess(RhinoEnvironment.java:714)
com.glide.script.ARhinoScope.checkScriptableAccess(ARhinoScope.java:134)

 

Is there something else I need to do to access script include CWMFolderUtil?

 

Also, once I create a folder, how can I create documents from a template in that folder? Do I substitute the folder id for space id in the call to sn_cwm.CWMTemplateService().createFromTemplate?

 

Thank you,

Michele

 

Sunil B N
ServiceNow Employee
ServiceNow Employee

It's a cross scope access issue. Please make sure you are calling within CWM scope.. Collaborative work management scope.

Sorry, but how do I set scope in a script?

 

Thank you