Scripting creating of service portal pages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2022 10:29 AM
We are looking for AN EASY WAY to create new service landing pages in our service catalog. Essentially what we want is to have a master portal page that would be used as the basis of all other pages. Content would then also need to be pushed to the HTML widgets on the page to update them. Is there AN EASY WAY to script having the master page cloned, renamed, and then the HTML widgets text updated? I'm thinking it may be more than we are probably going to be able tackle in-house.
Sample master landing page. Title is one HTML widget. Two other HTML widgets underneath. This is what we would need to have scripted to update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 03:19 AM
Depatable.
You can write a script to copy the records and I might consider it easyish, but sound like you'd have something pretty difficult to manage if there's a lot of widgets and pages created.
I, while not a portal expert, would probably try to make the HTML widget dynamic. I can't really give you a good example since I've never done something like this, but basically the HTML widget is already getting it's HTML value dynamically by checking the options of the instance it's connected to.
So, you could technically set options on the instance so that there's more than 1 possible HTML result and then display what you need based on the logged in user.
However there's a chance that someone overwrites the whole option section accidentally and it's also harder to modify the content as you can't really do it on the HTML widget.
But things to consider when creating a script to copy the existing pages and instances:
1. Insert a copy of the main page after changing the name.
2. insert a copy of the instance.
3. insert a copy of the column.
4. Insert a copy of the row.
5. Insert a copy of the container.
Basically it just has a multilevel relationship and you'd have to create connections between the inserted records. Since you have at least three widgets, you'll need to do some things three times depending on your rows and columsn.
Here's an example script that copies the above mentioned parts once. Note that I did not test this at all and it's just to give you an idea.
var page = new GlideRecord('sp_page');
page.get('PAGE_SYS_ID');
page.title = 'NEW TITLE';
page.id = 'NEW ID';
var newPage = page.insert();
var container = new GlideRecord('sp_container');
container.get('CONTAINER_SYS_ID');
container.sp_page = newPage;
var newContainer = container.insert();
var row = new GlideRecord('sp_row');
row.get('ROW_SYS_ID');
row.sp_container = newContainer;
var newRow = row.insert();
var column = new GlideRecord('sp_column');
column.get('COLUMN_SYS_ID');
column.sp_row = newRow;
var newColumn = column.insert();
var instance = new GlideRecord('sp_instance');
instance.get('INSTANCE_SYS_ID');
instance.sp_column = newColumn;
var newInstance = instance.insert();