Hello,
I'm having some problems adding a linked item to the Project Management tab via a script. I have the relationship set up properly and I'm able to add them manually.
Here's the line of code that should be adding the linked item:
item.project.addTask(mechItem);
mechItem is defined earlier in the code and successfully finds the workspace record.
This is the error that is thrown:
com.dms.scripting.exceptions.ScriptModelException: Could not save new tasks: []
Any ideas? Thanks!
Solved! Go to Solution.
Solved by rsbishop. Go to Solution.
For Linked Items in a Project tab, you first need to create the Item.
There should be a createNewItem Library Script that has some instructions on how to call it.
Then once your new items is created you can add it to your project.
Here is an example:
Remember to import the CreateNewItem library script.
var prjItem = null; var newItemProps = []; //Array of Properties for your new Linked Item var _start = new Date();//Today var _duration = 3;//Days var _end = new Date(_start.getTime() + _duration*24*60*60*1000);//Add _duration to _start //TODO: Change this to match the system name of your task worksapce var taskWSName = 'WS_PROJECT_TASKS';
//Build the array of Field Names for your new Item newItemProps.NAME = 'Some New Name'; newItemProps.DESCRIPTION = 'Some Description'; newItemProps.START_DATE = _start; newItemProps.END_DATE = _end; newItemProps.SOME_OTHER_FIELD = 'Some Value'; //TODO: Add any other fields you want to set on your new Lined //Create the new Linked Item prjItem = createNewItem(taskWSName, newItemProps); item.project.addTask(prjItem , _start, _end, '0');
//Once you create and add your Task (prjItem) you can add Milestones to it or other info,
//but I'd put that in an OnCreate script vs. this one.
I ended up solving the problem. The script was looping through items and attempted to add the same item to project management twice. I added some logic to ensure it only tries to add each item once and it works as intended now.
Thanks