- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 12:02 PM
Hi,
I have a requirement that if a non-admin user tries to save/update an existing project record as a template (Template - Save as Template) with the help of OOB context menu, an error message should pop-up as "Template creation has been disabled for Projects". Also, the page should redirect to the current project form.
Below is my business rule that I have written on the template table for this restriction:
Name: Template Restriction
Table: Template (sys_template)
When to Run: Before Insert and Update
Condition: !gs.hasRole('admin')
Script:
function onBefore(current, previous)
{
//This function will be automatically called when this rule is processed.
var name = current.table;
if(name == 'pm_project')
{
var url = 'pm_project.do?sys_id' + name.sys_id;
gs.addErrorMessage("Template creation has been disabled for Projects");
current.setAbortAction(true);
action.setRedirectURL(url);
}
if(name == 'pm_project_task')
{
var url2 = 'pm_project_task.do?sys_id' + name.sys_id;
gs.addErrorMessage("Template creation has been disabled for Project Tasks");
current.setAbortAction(true);
action.setRedirectURL(url2);
}
}
I am able to restrict the save as a template but unable to bring back user to the current project form. Kindly help!!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 07:22 PM
Hi Kunal,
gs.setRedirect will also not work in this specific use case what you have as the post processing submission is on the template table.
You have to adjust the condition in the UI context menu from where the template action take place.
On another note, there is an error here in this line of code
var url2 = 'pm_project_task.do?sys_id' + name.sys_id; should be var url2 = 'pm_project_task.do?sys_id =' + name.sys_id;
I hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 12:12 PM
Hi Kunal,
use gs.setRedirect instead of action.setRedirect
gs.setRedirect(url2);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 12:55 PM
Srinivas is right. The action.setRedirectURL() is only for UI actions I believe. There should be some warning/error in the Logs if you try to use that for a business rule.
Warren
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 06:42 PM
Hi Srinivas,
It seems even after using gs.setRedirect(url) and gs.setRedirect(url2), the user is not getting redirected to the Project/Project task page.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 07:22 PM
Hi Kunal,
gs.setRedirect will also not work in this specific use case what you have as the post processing submission is on the template table.
You have to adjust the condition in the UI context menu from where the template action take place.
On another note, there is an error here in this line of code
var url2 = 'pm_project_task.do?sys_id' + name.sys_id; should be var url2 = 'pm_project_task.do?sys_id =' + name.sys_id;
I hope this helps