How to add a field on Project template pop up
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 05:11 AM
Hi folks,
When I create a new project based on a template, I have the following requirements:
1. add the Company field on the template pop up -> done by updating the related UI macro create_project_from_template (78ff33d1c3303100b0449f2974d3aec7)
2. once the Template and Company are selected, the Company is filled out on the newly created project. -> failed.
In order to fill out the Company on the Project record, I know that I need to update the processing script in the UI page create_project (07009e91c3222100b0449f2974d3aeb6) but it uses the object GlideProjectTemplate which is not available to developers from my understanding.
OOTB UI page create_project
HTML
<?xml version="1.0" encoding="utf-8"?> <j:jelly xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null" trim="false"> <g:messages> Please select a template Enter date in {0} format The following mandatory fields are not filled in Saving Start Date Project template Project Name </g:messages> <g2:evaluate var="jvar_config_id" jelly="true"> //Get TeamSpace configuration which current template table is associted with var config_id = SNC.PPMConfig.getConfigId('${sysparm_template_table}'); config_id; </g2:evaluate> <g:set_if var="jvar_start_date" test="${empty(sysparm_start_date)}" true="" false="${sysparm_start_date}" /> <g:ui_form> <input type="hidden" name="create_project" id="create_project" value="false"/> <input type="hidden" name="template_action" id="template_action" value="${sysparm_template_action}"/> <input type="hidden" name="has_children" id="has_children" value="${sysparm_has_children}"/> <input type="hidden" name="project_id" id="project_id" value="${sysparm_project_id}"/> <input type="hidden" name="config_id" id="config_id" value="$[jvar_config_id]"/> <input type="hidden" name="template_table" id="template_table" value="${sysparm_template_table}"/> <input type="hidden" name="is_planning_console" id="is_planning_console" value="${sysparm_is_planning_console}"/> <div id="load_mask_container" style="display: none;"> <span class="icon icon-loading"></span> </div> <div id="ui_page_content" class="ui_page_content"> <g:create_project_from_template/> </div> </g:ui_form> <style> #load_mask_container { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; height: 100%; width: 100%; background-color: #ffffff; position: absolute; top: 0; left: 0; opacity: 0.80; z-index: 1000; align-items: center; -ms-flex-align: center; justify-content: center; -ms-flex-pack: center; } </style> </j:jelly> |
Client script
function onCancel() { GlideDialogWindow.get().destroy(); return false; } function actionOK() { var invalidFields = []; var form = document.forms['form.' + '${sys_id}']; var template_action = form["template_action"].value; var has_children = form["has_children"].value; if(!form["is_planning_console"].value){ form["is_planning_console"].value = window.location.href.indexOf('sysparm_planning_console=true')==-1?false:true; } if (template_action != "apply_template") { var project_name = form["project_name"].value; if (!project_name) invalidFields.push(getMessage("Project Name")); } //validate start_date and template_id var template_id = form["template_id"].value; if (!template_id) { invalidFields.push(getMessage("Project template")); } else { addInput(form, "HIDDEN", "project_template", template_id); } if(has_children != "true") { var startDate = getDateFromFormat(trim(gel('project_start_date').value), g_user_date_time_format); if(startDate <= 0) { invalidFields.push(getMessage("Start Date")); } } if (invalidFields.length > 0) { var theText = invalidFields.join(', '); theText = new GwtMessage().getMessage('The following mandatory fields are not filled in: {0}', theText); alert(theText); return false; } if (template_action == "apply_template") addInput(form, "HIDDEN", "sys_action", "apply_template"); else addInput(form, "HIDDEN", "sys_action", "create_project"); showLoadMask(); return true; } function showLoadMask() { var loadMask = document.getElementById('load_mask_container'); loadMask.style.display = 'flex'; } |
Processing script
var project = null; var projectTable = SNC.PPMConfig.getProjectTable(template_table); if(sys_action != "undefined"){ template_action = sys_action; } if(typeof project_start_date == "undefined"){ project_start_date = ""; } if (template_action == "create_project") { project = GlideProjectTemplate.createProject(project_template, project_name, project_start_date); if (project != null && project.isValid()) { if(is_planning_console == 'true'){ response.sendRedirect("blank.do#sysparm_sys_class_name="+projectTable+"&sysparm_planning_console_sys_id=" + project.getUniqueValue()); } else{ response.sendRedirect(projectTable + ".do?sys_id=" + project.getUniqueValue()); } } } else if (template_action == "apply_template" && project_id ) { GlideProjectTemplate.apply(project_template, project_id, project_start_date); new ProjectPortfolioUtils().refreshProjectByProjectId(project_id,projectTable); if(is_planning_console == 'true'){ response.sendRedirect("gantt.do?sysparm_sys_class_name="+projectTable+"&sysparm_sys_id=" + project_id); } else{ response.sendRedirect(projectTable + ".do?sys_id=" + project_id); } } else { response.sendRedirect(projectTable + "_list.do"); } |
Has anyone come across that issue? It is not related to Project specifically but in a broad sense to templates. My hunch is that the requirement of adding a field on a template pop up must have been encountered in the past.
Any help or feedback would be appreciated.
Best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 05:27 AM
It seems like a lot of code for something that won't save the users any time or convenience.
METHOD 1 - User selects company on pop up
METHOD 2 - User selects company on project form
In either case clicks required to select a company are the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 08:29 AM
Hi Rob,
the code I shared is OOTB, but requires a plugin activation, I think Project Management. I added it in case someone wants to check it quickly.
Regarding your comments:
- "METHOD 1 - User selects company on pop up" -> I added Company on the pop up. The remaining action is then to submit it with the form but I cannot access the GlideProjectTemplate object.
- "METHOD 2 - User selects company on project form" -> we have a data policy that makes the Company field mandatory upon insert. So I need the Company field on the pop up, else no record will be created.
Best regards
Maron