<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Trying to apply project template in UI action in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498335#M155261</link>
    <description>&lt;P&gt;I should've read your original post carefully. I think applying Project Templates is different than a regular Template listed on the sys_template table.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;This is a shot in the dark, but you could try the code below. The ProjectWorkbenchService Script Include appears to have a method that might meet your needs.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1505765692994363 jive_text_macro" data-renderedposition="92_8_1192_608" jivemacro_uid="_1505765692994363"&gt;&lt;P&gt;//client-side 'apply_click'function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function apply_click() {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (confirm('This action will apply the template specified in the Project Template field. &amp;nbsp; Please confirm to proceed') == false) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false; //Abort submission&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; //call the UI action and skip the click function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; gsftSubmit(null, g_form.getFormElement(), 'apply_template'); //must call the action name above&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Code that runs without the click function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Ensure there are no errors on submission&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if (typeof window == 'undefined')&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; runApplyTemplate();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Server-side function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function runApplyTemplate() {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (function executeRule(current, previous /*null when async*/ ) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tname = current.u_project_template.name;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tsysid = current.u_project_template.sys_id;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tdate = gs.getDateTime();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var url;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.u_rank = "4";&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new ProjectWorkbenchService().applyTemplateForProject(tsysid, current.sys_id, current.start_date);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.addInfoMessage("Template " + tname + " applied " + tsysid);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.update();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; url = current.getTableName() + '.do?sys_id=' + current.sys_id.toString() + '&amp;amp;sysparm_view=';&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; action.setRedirectURL(url);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; })(current, previous);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 18 Sep 2017 20:15:29 GMT</pubDate>
    <dc:creator>Justin Abbott</dc:creator>
    <dc:date>2017-09-18T20:15:29Z</dc:date>
    <item>
      <title>Trying to apply project template in UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498332#M155258</link>
      <description>&lt;P&gt;I am trying to use a UI action (button) to apply a project template to an existing (blank) project. &amp;nbsp; &lt;/P&gt;&lt;P&gt;I created a reference field "u_project_template" on the project form that allows the user to select the appropriate template from the Project Template form.&lt;/P&gt;&lt;P&gt;The UI action include a client &amp;amp; server side script. &amp;nbsp; The pop-up confirmation works, the field that I set in the server side script works and the info message appears at the end with the correct variable values (project template sys_id and project template name). &amp;nbsp; However, the template does not apply. &amp;nbsp; (No project tasks and no other field values are set as they are defined in the project template)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've looked and looked and found other references to applying a template via the applyTemplate() function, but I can't get this to work with project templates. &amp;nbsp; Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the script that I've been working on:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----SCRIPT BEGIN-----&lt;/P&gt;&lt;P&gt;//client-side 'apply_click'function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function apply_click(){&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if(confirm('This action will apply the template specified in the Project Template field. &amp;nbsp; Please confirm to proceed') == false){&lt;/P&gt;&lt;P&gt;return false; &amp;nbsp; //Abort submission&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//call the UI action and skip the click function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gsftSubmit(null, g_form.getFormElement(),'apply_template'); //must call the action name above&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Code that runs without the click function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Ensure there are no errors on submission&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if(typeof window == 'undefined')&lt;/P&gt;&lt;P&gt;runApplyTemplate();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Server-side function&lt;/P&gt;&lt;P&gt;function runApplyTemplate(){&lt;/P&gt;&lt;P&gt;(function executeRule(current, previous /*null when async*/) {&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var tname = current.u_project_template.name;&lt;/P&gt;&lt;P&gt;var tsysid = current.u_project_template.sys_id;&lt;/P&gt;&lt;P&gt;var tdate = gs.getDateTime();&lt;/P&gt;&lt;P&gt;var url;&lt;/P&gt;&lt;P&gt;current.u_rank = "4";&lt;/P&gt;&lt;P&gt;current.applyTemplate('tname');&lt;/P&gt;&lt;P&gt;gs.addInfoMessage("Template "+tname+" applied "+tsysid);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;current.update();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;url = current.getTableName() + '.do?sys_id=' + current.sys_id.toString() + '&amp;amp;sysparm_view=';&lt;/P&gt;&lt;P&gt;action.setRedirectURL(url);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;})(current, previous);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;-----SCRIPT END-----&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 19:34:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498332#M155258</guid>
      <dc:creator>michaelsharp</dc:creator>
      <dc:date>2017-09-18T19:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to apply project template in UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498333#M155259</link>
      <description>&lt;P&gt;Where you're applying the template, shouldn't the tname variable &lt;EM&gt;not&lt;/EM&gt; be in quotes? Check out line 37 below.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_15057642901587538 jive_macro_code jive_text_macro" data-renderedposition="50_8_1192_816" jivemacro_uid="_15057642901587538" modifiedtitle="true"&gt;&lt;P&gt;//client-side 'apply_click'function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function apply_click() {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (confirm('This action will apply the template specified in the Project Template field. &amp;nbsp; Please confirm to proceed') == false) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false; //Abort submission&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; //call the UI action and skip the click function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; gsftSubmit(null, g_form.getFormElement(), 'apply_template'); //must call the action name above&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Code that runs without the click function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Ensure there are no errors on submission&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if (typeof window == 'undefined')&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; runApplyTemplate();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Server-side function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function runApplyTemplate() {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (function executeRule(current, previous /*null when async*/ ) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tname = current.u_project_template.name;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tsysid = current.u_project_template.sys_id;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tdate = gs.getDateTime();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var url;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.u_rank = "4";&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.applyTemplate(tname);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.addInfoMessage("Template " + tname + " applied " + tsysid);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.update();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; url = current.getTableName() + '.do?sys_id=' + current.sys_id.toString() + '&amp;amp;sysparm_view=';&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; action.setRedirectURL(url);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; })(current, previous);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2017 19:52:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498333#M155259</guid>
      <dc:creator>Justin Abbott</dc:creator>
      <dc:date>2017-09-18T19:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to apply project template in UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498334#M155260</link>
      <description>&lt;P&gt;It doesn't work with or without quotes. &amp;nbsp; I've been playing with different syntax to try and figure this out to no avail.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;I'm not a developer, but have hacked my way into several other UI actions/scripts, etc, but this one evades me.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Sep 2017 20:00:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498334#M155260</guid>
      <dc:creator>michaelsharp</dc:creator>
      <dc:date>2017-09-18T20:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to apply project template in UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498335#M155261</link>
      <description>&lt;P&gt;I should've read your original post carefully. I think applying Project Templates is different than a regular Template listed on the sys_template table.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;This is a shot in the dark, but you could try the code below. The ProjectWorkbenchService Script Include appears to have a method that might meet your needs.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1505765692994363 jive_text_macro" data-renderedposition="92_8_1192_608" jivemacro_uid="_1505765692994363"&gt;&lt;P&gt;//client-side 'apply_click'function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function apply_click() {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (confirm('This action will apply the template specified in the Project Template field. &amp;nbsp; Please confirm to proceed') == false) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false; //Abort submission&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; //call the UI action and skip the click function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; gsftSubmit(null, g_form.getFormElement(), 'apply_template'); //must call the action name above&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Code that runs without the click function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Ensure there are no errors on submission&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if (typeof window == 'undefined')&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; runApplyTemplate();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Server-side function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function runApplyTemplate() {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (function executeRule(current, previous /*null when async*/ ) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tname = current.u_project_template.name;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tsysid = current.u_project_template.sys_id;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tdate = gs.getDateTime();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var url;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.u_rank = "4";&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new ProjectWorkbenchService().applyTemplateForProject(tsysid, current.sys_id, current.start_date);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.addInfoMessage("Template " + tname + " applied " + tsysid);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.update();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; url = current.getTableName() + '.do?sys_id=' + current.sys_id.toString() + '&amp;amp;sysparm_view=';&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; action.setRedirectURL(url);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; })(current, previous);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2017 20:15:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498335#M155261</guid>
      <dc:creator>Justin Abbott</dc:creator>
      <dc:date>2017-09-18T20:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to apply project template in UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498336#M155262</link>
      <description>&lt;P&gt;Justin, that did it! &amp;nbsp; Thank you so much!&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Sep 2017 22:31:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498336#M155262</guid>
      <dc:creator>michaelsharp</dc:creator>
      <dc:date>2017-09-18T22:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to apply project template in UI action</title>
      <link>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498337#M155263</link>
      <description>&lt;P&gt;For the record, here is the final script:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//client-side 'apply_click'function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function apply_click(){&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if(confirm('This action will apply the template specified in the Project Template field. &amp;nbsp; Please confirm to proceed') == false){&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;return false; &amp;nbsp; //Abort submission&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//call the UI action and skip the click function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gsftSubmit(null, g_form.getFormElement(),'apply_template'); //must call the action name above&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Code that runs without the click function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Ensure there are no errors on submission&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if(typeof window == 'undefined')&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;runApplyTemplate();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//Server-side function&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;function runApplyTemplate(){&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;(function executeRule(current, previous /*null when async*/) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var tname = current.u_project_template.name;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var tsysid = current.u_project_template.sys_id;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var prjid = current.sys_id;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var tdate = current.start_date;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var url;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;new ProjectWorkbenchService().applyTemplateForProject(tsysid, prjid,tdate);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gs.addInfoMessage("Template "+tname+" applied "+" starting on "+tdate);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;current.update();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;url = current.getTableName() + '.do?sys_id=' + current.sys_id.toString() + '&amp;amp;sysparm_view=';&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;action.setRedirectURL(url);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;})(current, previous);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Sep 2017 22:49:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trying-to-apply-project-template-in-ui-action/m-p/1498337#M155263</guid>
      <dc:creator>michaelsharp</dc:creator>
      <dc:date>2017-09-18T22:49:09Z</dc:date>
    </item>
  </channel>
</rss>

