Add fields to bring to Project from Demand's "Create Project" UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 10:56 AM
Running on Istanbul, we have added custom fields to the Demand (dmn_demand) form. When the Demand's type is "Project", the UI Action for "Create Project" is now available, and when used the OOB fields are coming over to the newly created Project. I'd like to script in more to come over, but looking through the "Create Project" UI Action, it would seem that all of this is handled by the "AjaxCreateRelatedEntityFromDemand" script include that I rather not modify and edit if I don't have to.
Is there a system property somewhere that would allow me to enter in the element names of my new Demand fields, for the "AjaxCreateRelatedEntityFromDemand" script include to refer to and include in its process of creating the related Project?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 11:01 AM
Hi,
This can be done by modifying the below mentioned Script Include:
DemandToProjectCreationHelper
Replace "instance" in the above URL with your Instance Name.
As highlighted in the above screen shot, Replace your Project Table field and Demand Table field accordingly an this will Resolve your Issue.
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 11:09 AM
My version of that file looks differently, could it be because we are using Project Teamspaces?
var DemandToProjectCreationHelper = Class.create();
DemandToProjectCreationHelper.prototype = {
initialize: function() {
},
createProject: function (sysId) {
var sys_id = sysId, projId, projNumber, tableDisplayName;
var demand = new GlideRecord('dmn_demand');
demand.addQuery('sys_id', sys_id);
demand.query();
if(demand.next()) {
sys_id = demand.getValue("sys_id");
projId = demand.getValue("project");
var projectTable = "pm_project";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
projectTable = SNC.PPMConfig.getProjectTable(demand.sys_class_name);
}
if(sys_id && !projId) {
var project = new GlideRecord(projectTable);
project.initialize();
project.setValue("short_description", demand.getValue('short_description'));
project.setValue("primary_portfolio", demand.getValue("portfolio"));
if(project.isValidField('primary_program')){
project.setValue("primary_program", demand.getValue("primary_program"));
}
project.setValue("calculation_type", 'manual');
project.setValue("business_case", demand.getValue("business_case"));
var benefit = demand.financial_benefit;
if( JSUtil.notNil(benefit) && JSUtil.notNil(benefit.getCurrencyValue())) {
project.benefits = benefit.getCurrencyCode() + ';' + parseFloat(benefit.getCurrencyValue());
}
this._setProjectDatesAndDurationFromDemand(project, demand, projectTable);
projId = project.insert();
projNumber = project.getValue('number');
tableDisplayName = project.getClassDisplayValue();
if(JSUtil.nil(demand.related_records))
demand.related_records = projId;
else
demand.related_records = demand.related_records + "," + projId;
demand.project = projId;
demand.state = '8';
demand.stage = 'project';
demand.update();
var req = new GlideRecord("dmn_requirement");
req.addQuery("parent", sys_id);
req.query();
while(req.next()){
var sourceId = req.getUniqueValue();
req.parent = projId;
var newNumber = new NumberManager('dmn_requirement');
req.number = newNumber.getNextObjNumberPadded();
var reqId = req.insert();
GlideSysAttachment.copy('dmn_requirement', sourceId, 'dmn_requirement', reqId);
gs.log("Requirement created for Project " + project.number);
}
if(new GlidePluginManager().isActive('com.snc.financial_planning_pmo')){
this._updateFinancialRecords(sys_id, projId);
var budgetPlanner = new ITFMBudgetPlanner();
budgetPlanner.updateDemandBudgetKeysToProject(demand, projId);
}
var risk = new GlideRecord("risk");
risk.addQuery("state","!=","achieved");
risk.addQuery("task", sys_id);
risk.query();
while(risk.next()){
risk.task = projId;
if (new GlidePluginManager().isActive('com.snc.program_management'))
risk.top_task = projId;
risk.update();
gs.log("Risk updated for Project " + project.number);
}
var dec = new GlideRecord("dmn_decision");
dec.addQuery("parent", sys_id);
dec.query();
while(dec.next()){
var decSourceId = dec.getUniqueValue();
dec.parent = projId;
var decId = dec.insert();
GlideSysAttachment.copy('dmn_decision', decSourceId, 'dmn_decision', decId);
gs.log("Decision created for Project " + project.number);
}
}
}
return {'sys_id': projId, 'number': projNumber, 'label': tableDisplayName};
},
_setProjectDatesAndDurationFromDemand: function(project, demand, projectTable) {
if (demand.start_date.nil())
return;
var defaultProjectScheduleId = '7aa3e10c8f70010040f82ab2f0f9234d';
var scheduleId = SNC.PPMConfig.getProperty('com.snc.project.default_schedule', projectTable, defaultProjectScheduleId);
var util = new ProjectTaskManagerUtil();
var demandStart = new GlideDateTime();
demandStart.setDisplayValue(demand.getValue('start_date') + ' 00:00:00');
var startDateTime = util.getStartDateFromSchedule(scheduleId, demandStart.getDisplayValue());
var projectStartDateTime = new GlideDateTime();
projectStartDateTime.setDisplayValue(startDateTime);
project.setValue('start_date', projectStartDateTime);
if (!demand.requested_by.nil()) {
var demandEnd = new GlideDateTime();
demandEnd.setDisplayValue(demand.getValue('requested_by') + ' 00:00:00');
var endDateTime = util.RecalculateEndDateFromAbsoluteDurationPerSchedule(demandEnd.getDisplayValue(), new GlideDuration('1 00:00:00'), scheduleId);
var projectEndDateTime = new GlideDateTime();
projectEndDateTime.setDisplayValue(endDateTime);
project.setValue('end_date', projectEndDateTime);
var duration = util.RecalculateDurationFromEndDatePerSchedule(startDateTime, endDateTime, scheduleId);
var projectDuration = new GlideDuration();
projectDuration.setDisplayValue(duration);
project.setValue('duration', projectDuration.getValue());
}
},
_updateFinancialRecords:function(demandId, projectId){
var costPlan = new GlideRecord("cost_plan");
costPlan.addQuery("task", demandId);
costPlan.setValue('task', projectId);
costPlan.setValue('top_task', projectId);
costPlan.setWorkflow(false);
costPlan.updateMultiple();
var costBreakdowns = new GlideRecord("cost_plan_breakdown");
costBreakdowns.addQuery("task", demandId);
costBreakdowns.setValue('task', projectId);
costBreakdowns.setWorkflow(false);
costBreakdowns.updateMultiple();
var fundingRecs = new GlideRecord("project_funding");
fundingRecs.addQuery("task", demandId);
fundingRecs.setValue('task', projectId);
fundingRecs.setWorkflow(false);
fundingRecs.updateMultiple();
//Update estimated and budget costs
var project = new GlideRecord('pm_project');
project.get(projectId);
new PlannedTaskEntityUpdater().updatePlannedTaskEstimatedCost(project);
new PPMTaskEntityUpdater().updateProjectBudgetCost(project);
},
type: 'DemandToProjectCreationHelper'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 11:23 AM
Did you try updating the script as I mentioned above? Even I am on Istanbul, what I provided was a screen shot of a portion of the Script so I don't think it will be having any issues.
Please try once and let me know.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 11:28 AM
The issue is that I don't have a single table for Project or Demand, as we are using teamspaces. This UI Action shows up on normal Demand and Project forms, as well as the child Teamspace table forms.