- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 11:57 AM
Hi
Is there any way to apply the template on a change using rest api.
after querying the JSON output i have reached to below field. Does any one knows how to update this field?
"u_template": {"link": "XXX", "value": "yyyy"}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 12:38 PM
Hi Sanjeev,
Do you currently have a Business Rule or Client Script that will apply the template when the field is set from the UI? You could consider adding a business rule that applies the specified template when the u_template field changes. Sample code (untested😞
Condition: current.u_template.changes()
Script: current.applyTemplate(current.u_template.name);
If you do go this route, be aware that this will also execute for updates made from the UI, not just REST API requests. If you need more flexibility, it may be worth looking at Scripted REST APIs - you could create a rest method that allows you to apply a template to a record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 12:29 PM
Hi Sanjeev,
FYI - I just tried this using the REST API explorer doing a PUT request on change_request with sysparm_template=sys_id_of_template and id did not work.
REST API Explorer - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 12:38 PM
Hi Sanjeev,
Do you currently have a Business Rule or Client Script that will apply the template when the field is set from the UI? You could consider adding a business rule that applies the specified template when the u_template field changes. Sample code (untested😞
Condition: current.u_template.changes()
Script: current.applyTemplate(current.u_template.name);
If you do go this route, be aware that this will also execute for updates made from the UI, not just REST API requests. If you need more flexibility, it may be worth looking at Scripted REST APIs - you could create a rest method that allows you to apply a template to a record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 12:51 PM
Hi Josh,
Great solution. To make it "web driven only" you could add this to the condition
current.u_template.changes() && !gs.isInteractive()
Indicating this was NOT driven from the UI by a human being, but rather from an integration call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 02:10 PM
Hi Josh,
Thanks,
I am taking the rest API method. I have updated the u_template with the template ID.
Though it did not update the template values, I guess due to templates are client side. Wondering is there any way to reload the template values to the Change fields.