Hi all, I would like to create a workflow/suitesc...
# suitescript
d
Hi all, I would like to create a workflow/suitescript that creates a project task for a specific project if a check box is marked in an opportunity transaction form. The specific project is always the same. i.e.: Opportunity Project. The task would take the title of the opportunity record as its name, set status to in progress, and 1 hour of estimated work. Would you be able to help me with this workflow/suitescript?
b
did you want this realtime or scheduled.
d
@battk Realtime
b
then you will be looking to create a user event script. ideally using the after submit entry point
d
Here's a first draft of the script to accomplish the goal above. How does this look?
b
i dont think it will work, but its the correct general idea
notably your variable scoping should cause a issue in createProjectTask
you would eventually work those out after trying out the script
you should add some sort of entry condition so that the script doesn't run every time the opportunity is edited
the tranid may not be populated on create so you might have to lookup the value with a search
company is a select field, so use the internal id number with setValue
same thing with status, use internal id (probably
PROGRESS
)
enableSourc should be enableSourcing
d
Thanks for the feedback. Sorry for the following noob questions. Just started learning suitescript. What do you mean by variable scoping? Will the second function not be able to find the variable Opportunity? The script would run after edit, not create. The only condition however is if the “createtask” checkbox is marked. How can I set an entry condition to look for that before running and to make sure it doesn’t repeat itself? Would that be in the script itself or in NetSuite after I upload the script? I updated the setValue for company to the internal Id of the project. “59858” which is specific to the project i’d like to create the task for. When you say PROGRESS, is that what the internal id is for In Progress? I thought it would be a numerical number?
b
javascript uses functional scoping. checkbox, OppNum, OppTitle, and Opportunity are only defined within onAfterSubmit
d
Oh, okay, how do I get them into the second function?
b
id say function parameter
afterSubmit entry points have a type key defined on the context parameter https://system.na0.netsuite.com/app/help/helpcenter.nl?fid=section_4407992281.html add something like this to filter out context types
Copy code
if (context.type !== context.UserEventType.EDIT) {
  return;
}
you can also do it on the script deployment record if you really only ever want it to run on EDIT
'PROGRESS'
is the internal id value of the
In Progress
select option. internal ids aren't all number formatted strings
d
@battk Hey, so I made adjustments to the script I mentioned previously. Thanks again for the feedback. However, I'm getting an error from NetSuite when I upload it: "SuiteScript 2.0 entry point scripts must implement one script type function." Do you have any thoughts on this?
Create Project Task from Opportunity Record
b
you may want to start reading the suitescript 2.0 introduction: https://system.na0.netsuite.com/app/help/helpcenter.nl?fid=chapter_4387172221.html
your specific problem is that your script is currently structured as a suitescript 1 script but that jsdoc annotation at the top says that it is a suitescript 2.0 script
the documentation for user event scripts has an example of how your script should be structured: https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=section_4387799721.html
that said, in general, your script mixes suitescript 1 and suitescript 2 apis. choose one, you cant use both