Import projects from xls into servicenow pm_project - how can we apply template for the import?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2024 04:10 AM - edited ‎01-05-2024 04:11 AM
Hello Developers/SPM experts,
I have around 200+ projects in an xls which I need to import in pm_project table. I am using the xls template provided by ServiceNow for this activity.
As we import the projects, I also want to apply templates to each project that is imported. This means that we also get the Gantt chart for each imported project and the user NEED NOT have to click and create this gantt chart.
Is it possible to do this in an import xls?
Best Regards,
Ashwini Pingle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2024 12:07 AM
To import projects from an xls file into ServiceNow's pm_project and apply a template, follow these steps:
1. Prepare your xls file: Ensure that your xls file is properly formatted and contains all the necessary information for your projects. This includes fields like project name, start date, end date, project manager, etc.
2. Create a Data Source: In ServiceNow, navigate to System Import Sets > Administration > Data Sources and create a new data source. Choose "File" as the type and upload your xls file.
3. Create an Import Set Table: Navigate to System Import Sets > Administration > Import Sets and create a new import set. Choose the data source you just created.
4. Create Transform Map: Navigate to System Import Sets > Administration > Transform Maps. Create a new transform map and link it to the import set table you created. Here, you can define how the data from your xls file maps to the fields in the pm_project table.
5. Apply Template: If you have a project template that you want to apply to the imported projects, you can do this in the transform map. In the "onBefore" or "onAfter" script, you can use the applyTemplate() method of the Project API to apply your template to each project. Here is a sample code:
javascript
var project = new GlideRecord('pm_project');
project.get(source.u_project_id);
var template = new GlideRecord('pm_project_template');
template.get('template_sys_id'); // replace 'template_sys_id' with the sys_id of your template project.applyTemplate(template);
project.update();
6. Run the Import: Once your transform map is set up, you can run the import. Navigate to System Import Sets > Load Data and select your import set. Click on "Load Data" to start the import process.
7. Verify the Import: After the import is complete, navigate to Project > Projects to verify that your projects have been imported correctly and that the template has been applied.
Remember to test this process in a sub-production instance before applying it in production.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2024 01:37 AM
Yes, it is possible to import projects from an xls file and apply templates to each project in ServiceNow. However, the process of applying templates to each project during import is not straightforward and requires some scripting. Here are the steps: 1. Import the xls file into a staging table in ServiceNow using Import Sets. 2. Create a transform map to map the fields from the staging table to the pm_project table. 3. In the transform map, create an onAfter script that applies the project template to each project after it is imported. You can use the applyTemplate() method of the Project API to apply a template to a project. Here is a sample code for the onAfter script: javascript (function runTransformScript(source, map, log, target /*undefined onStart*/ ) { var gr = new GlideRecord('pm_project_template'); gr.get('template_sys_id'); // replace 'template_sys_id' with the sys_id of the template you want to apply if (gr.isValid()) { target.applyTemplate(gr); } })(source, map, log, target); Please replace 'template_sys_id' with the sys_id of the template you want to apply. Please note that this script assumes that you have a single template that you want to apply to all projects. If you have different templates for different projects, you will need to modify the script to select the correct template based on some criteria. Also, please note that applying a template to a project will not automatically create a Gantt chart for the project. The Gantt chart is created when a user opens the project in the Project Workspace. However, once the template is applied, all the tasks and dependencies defined in the template will be created in the project, and they will be displayed in the Gantt chart when it is created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 11:04 PM
Hello @sumanta pal , @sourav1999 ,
I tried both your scripts in transform map, one at a time.
OnBefore and OnAfter both were tried.
The table name for templates is project_template (and not pm_project_template)
Following is the latest script i have