The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Ashok Madhavan1
ServiceNow Employee
ServiceNow Employee

Pre and Post Provision operation with Templates

In this article we will see how to do pre and post provision operations with the templates.

The flow would be like this:

  • Create a catalog item and ingest a template.
  • Add a Pre-Provision operation. In this sample we will call a simple workflow.You can call workflows, Cloud API, Script includes as well.
  • Add a Post-Provision operation. In this sample we will call a simple workflow. You can call workflows, Cloud API, Script includes as well.

Get to Cloud Admin Portal first. Then get to Cloud Catalog Items. Then create a new catalog item. I am naming it 'Pre and Post Provision Sample'. 

find_real_file.png

I am choosing an ARM template. You can go for CFT, GDM or any template. Save it.

Then go to the 'Cloud Templates' tab and upload/Provide URL for the ARM template and save it. It will read the template and parse the variables.

find_real_file.png

Then click 'Activate' button to create the variables, variable sets etc on the catalog item.

Let us take a short detour to look at the Pre and Post operations flows we are going to call.

For this exercise we have created two workflows, one for Pre and one for Post provision operation. Both these are basic workflows. In your case you would be using an appropriate workflow.  Instead of workflow, you can use a Cloud API or a script include call as applicable.

find_real_file.png 

 Let us look at the Pre-Process WF first. It is a simple workflow that looks like this:

find_real_file.png

It basically logs the inputs that are sent to the workflow. And very importantly returns 'success' as the return. This is critical and this tells us that the workflow execution was successful.

This workflow takes in a single input 'u_payload'. The inputs can be seen here. Click on the properties and you can view it.

find_real_file.png

 

 The 'Log Workflow Inputs' step looks like this:

find_real_file.png

In a real life scenario, there could be multiple steps and each one doing something pertinent to your use case.

The 'Return Value' step looks like this. This is important and needed.

find_real_file.png

 

The Post-Process WF is very similar to Pre-Process WF. Am not showing the WF here.

Now let us get back to our catalog item.

After you have hit the 'Activate' button, you will see that there are two tabs in the related lists. "Pre Provision Operation" and "Post Provision Operation". This is the place where you add the Pre and Post provision operations.

 

find_real_file.png

Let us click on 'Pre Provision Operation' tab. You would see a 'new' button there.

find_real_file.png

Click on the 'New' button to add a Pre Provision step. A create form would show up like this:

find_real_file.png

In this example, we will choose Workflow. You can choose as per your use case.

find_real_file.png

Choose 'Workflow' and then click on the 'search button' for choosing which workflow.

find_real_file.png

Choose Pre-Process WF and hit OK. In your instance, you would be choosing an appropriate workflow.

 Then click Submit as shown below.

find_real_file.png

This Pre-Process WF takes in a parameter called 'u_payload'. We need to map this 'u_payload' attribute to an appropriate input from the catalog item. For this, click the 'Manage Attributes' link as shown below:

find_real_file.png

The 'Manage Attributes' screen will show up. You need to choose the 'Pre Provision' operation call as shown below.

find_real_file.png

CMP reads the inputs for the workflow and auto-adds them to the operation attributes. This way user does not need to add them manually. Then click on the 'u_payload' operation attribute. 

In this exercise, We will map the u_payload to StackName. You can change it right here to 'S{parameter.StackName}' or click on the 'u_payload'.

find_real_file.png

Click on Update.

Then click on the 'Apply Changes'. 

find_real_file.png

 The same set of changes need to be done for the Post-Provisioning operation as well. I will leave that as an exercise to the user.

When you are done with it, it would look like this:

find_real_file.png 

Mark the catalog item as active so that end users can order it.

find_real_file.png

 

Now get into the Cloud User Portal (or via url https://your_server_here/cloud_portal). Get to the 'Catalog' section.

find_real_file.png

Choose the 'Pre and Post Prov Sample' catalog item.

Put in proper values for all fields. For the StackName i am using 'TestPreAndPost'. 

find_real_file.png

Then click the submit button as indicated below.

find_real_file.png

 

You will then see that the Pre-Provision step is getting executed.

find_real_file.png

After this call is completed, you will see the template getting executed.

find_real_file.png

When the template is provisioned and the targeted discovery of the resources is completed, the Post-Provisioning step gets executed.

find_real_file.png

 

We just saw how to enable Pre and Post provisioning operations on a template driven catalog item. 

 

 

Comments
arjunalagar
Kilo Contributor

Hi Ashok,

Thanks for the article. Will we be able to create catalog tasks using the Pre/Post Provisioning operations? 

Thanks & Regards,

Arjun

Brent Langdon
Tera Contributor

Thanks!  This was helpful.  Two issues that I hit along the way:

I am new to using Workflows, and I wasted the better part of a day trying to troubleshoot an issue that turned out to be that I did not Publish the Workflow.  ServiceNow just reported a generic error "did not start all flows".  Publishing the Workflow fixed this.

When I created my Workflow, I selected the Table "Requested Item [sc_req_item]" based on some other info I found.  Then instead of the "Inputs" tab, this shows a "Catalog Variables" tab.  I then wasted more time trying to figure out how to populate these variables and access them from the script.  After recreating my Workflow and selecting "Global [global]", I was able to follow this example.

I am curious if I can call a Script Include directly instead of using a Workflow.  When I tried the "Instance Script" option, it seemed like it was trying to call a method on the "vm" object.  In my case I have a Catalog Item based on a Terraform template and I want to invoke a Ansible Tower Template after the environment is provisioned.

rohinip
Tera Contributor

hi Arjun,

Were you able to successfully create tasks. I am struggling with passing RITM Sys_id.

Thanks,

Rohini

Version history
Last update:
‎09-30-2019 10:23 AM
Updated by: