How to start an Alfresco Workflow through Javascript adding a resource - javascript

Starting using a rule and a simple javascript in Alfresco is quite easy but i'm stuck on trying to start a workflow through javascript adding a resource.
My goal is to add the document (or documents) used to start the flow, so i can obtain a reference in the "OW_ATTACHMENTS" of the Alfresco BPM of the Alfresco WorkDesk.
I've tried many times with the bpm:workflowpagckage or bpm:package with no luck....help!
Edit:
function startWorkflow(name,docNode)
{
var workflow = actions.create("start-workflow");
workflow.parameters["bpm:workflowPackage"] = docNode;
workflow.parameters.workflowName = "activiti$AdHocactivitiTimer";
workflow.parameters["bpm:assignee"] = people.getPerson("admin");
workflow.parameters["bpm:workflowDescription"] = "test";
workflow.parameters["bpm:workflowPriority"] = "2";
workflow.parameters["bpm:sendEMailNotifications"] = true;
workflow.parameters["initiator"] = people.getPerson("admin");
var today = new Date();
var duedate = today.getDate() + 1;
workflow.parameters["bpm:workflowDueDate"] = duedate;
workflow.execute(document);
}
function main()
{
var docNode = search.findNode(document.nodeRef);
var name = document.name;
startWorkflow(name,docNode);
}
main();
thanks!

The bpm:package or bpm_package is not available before start.
So what happens you're document is added to bpm_package.
And in your workflow you can access bpm_package as a variable. And with bpm_package.addNode(doc); you can add nodes.
These nodes can be found through search/childbynamepath/xpath etc.
If you don't use the action the other way is:
var workflowAction = workflow.getDefinitionByName('activiti$AdHocactivitiTimer');
var package= workflow.createPackage();
package.addNode(document);
workflowAction.startWorkflow(package, parameters);

Related

TypeError: calendar.getEvents is not a function

I'm using google apps script and attempting to check if an event exists. I'm using some code from this question and I'm not sure why the script is telling me that getEvents() is not a function as it is here in google documentation
My code looks like this
function doesEventExist() {
var fromDate = new Date(); //This is Today
var toDate = new Date();
toDate.setDate(toDate.getDate()+20);
Logger.log("From "+fromDate+" to "+toDate);
var calendar = CalendarApp.getCalendarsByName("CalendarName");
if(calendar == null){
Logger.log("Unable to connect to calendar");
exit();
}
var events = calendar.getEvents(fromDate,toDate);
for(var i=0; i<events.length;i++)
{
var ev = events[i];
var title = calendar.getEventSeriesById(ev.getId()).getTitle();
if (title.indexOf(Event Name)>-1){
var start = ev.getStartTime();
Logger.log("Found Event");
return true;
var id = ev.getId();
var date = ev.getStartTime();
var desc = ev.getDescription();
}
}
}
Does the getEvents() function no longer exist or is there an issue with my code?
Edit: as someone commented getCalendarsByName() returns an array to I ended up setting the variable calendar to calendars[0]
I'm leaving #nbookmans comment as an answer for Stack workflow purposes.
As stated in the documentation, getCalendarsbyName() returns:
Calendar[] — all calendars with this name that the user can access
Which is an array of Calendars. In order to get the events, you have to iterate over the array.

Mirth - Send multiple HL7 messages during one polling interval

In Mirth, I have a JavaScript Reader connector and in the source, I have a call to a stored procedure. This procedure returns multiple rows. Is there any way to script it so that for each row returned from the procedure, I can generate the message and send appropriately? The other option that I am already aware of is to script it to generate only 1 message and have the polling interval set to every 100ms or so in addition to changing the procedure. Any help or insight would be greatly appreciated.
var procedure = 'exec dbo.mystoredprocedure';
objresult = dbConn.executeCachedQuery(procedure);
while (objresult.next())
{
var msg = <HL7Message/>;
msg.MSH['MSH.1'] = '|';
msg.MSH['MSH.2'] = '^~\\&';
msg.MSH['MSH.3'] = 'MedicalRecords';
msg.MSH['MSH.4'] = 'Application';
msg.MSH['MSH.5'] = 'Test';
msg.MSH['MSH.6'] = 'Something';
msg.MSH['MSH.7'] = DateUtil.getCurrentDate("yyyyMMddHHmmssSSS");
msg.MSH['MSH.8'] = '';
msg.MSH['MSH.9']['MSH.9.1'] = 'ADT';
msg.MSH['MSH.9']['MSH.9.2'] = 'A08';
msg.MSH['MSH.10'] = DateUtil.getCurrentDate("yyyyMMddHHmmssSSS");
msg.MSH['MSH.11'] = 'P';
msg.MSH['MSH.12'] = '2.5';
.
.
.
.
return msg;
}
Yes, you can return a List with multiple messages. Each element in the list will be dispatched to the channel as a separate message.
Great thanks! I did some digging and found what I was looking for.
var messages = new java.util.ArrayList();
messages.add(message1);
messages.add(message2);
return messages;

Google Script not Appending Spreadsheet

I'm trying to write a little script to make my coworkers and mine lives easier. I am trying to append lines to a spreadsheet based on information entered into a custom form. The code posted below just the doPost block which should be appending the google spreadsheet.
function doPost(form) {
var PN = form.PartNumber;
var REV = form.Revision;
var DATE = form.RevisionDate;
var DESC = form.Description;
var NOTE = form.PartNotes;
var URL = form.myFile.getURL();
var ss = SpreadsheetApp.openById("ID HERE"); // removed ID for sake of safety (let me be paranoid)
var sheet = ss.getSheetName('Uploads');
sheet.appendRow([PN,REV,DATE,DESC,NOTE,URL]);
}
I am unsure why it isn't writing to the spreadsheet but it isn't throwing me any errors. If you can offer any insight as to what is wrong I would greatly appreciate it; there are many guides online but most seem to be based on deprecated functions/code/etc.
Thanks for your time.
Instead of using doPost, set up a "On form submit" trigger.
You need to get the namedValues to be able to pull specific values and take the first output.
Also, it should be "getSheetByName('Uploads')" .
As pointed out in the previous answer, it is unclear what you are trying to achieve by "form.myFile.getURL();" If you want to get the form url you might as well create it as a string, as it always stays the same.
Here is a working example of your code:
function doPost(form) {
var formResponses = form.namedValues;
var PN = formResponses.PartNumber[0];
var REV = formResponses.Revision[0];
var DATE = formResponses.RevisionDate[0];
var DESC = formResponses.Description[0];
var NOTE = formResponses.PartNotes[0];
//var URL = form.myFile.getURL(); //Not sure what you are tyring to get here as form URL will always be the same.
var URL = "Your form's url"; //You can put the form url in here so it will be pushed in to every row.
var ss = SpreadsheetApp.openById("ID HERE"); // removed ID for sake of safety (let me be paranoid)
var sheet = ss.getSheetByName('Uploads');
sheet.appendRow([PN,REV,DATE,DESC,NOTE,URL]);
}
The form fields are nested in a "parameter" property in the doPost parameter.
So, you should access them using:
function doPost(form) {
var actualForm = form.parameter;
var PN = actualForm.PartNumber;
//etc
To double check all parameters your receiving and their names, you could append to your sheet everything stringfied, like this:
sheet.appendRow([JSON.stringify(form)]);
--edit
This form.myFile.getURL() also looks odd. I guess another good debugging trick you could do is to wrap everything in a try-catch and email yourself any errors you get. For example:
function doPost(form) {
try {
//all your code
} catch(err) {
MailApp.sendMail('yourself#etc', 'doPost error', err+'\n\n'+JSON.stringify(form));
}
}
On form submit
onFormSubmit works. "doPost" looks wrong.
Simple example:
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendGoogleForm")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function SendGoogleForm(e)
{
try
{
Full example - Scroll down to the code http://www.labnol.org/internet/google-docs-email-form/20884/ (Note: example sends email)
Trigger docs: https://developers.google.com/apps-script/guides/triggers/events
Notes: I think the problem is doPost, Does it work with google Forms? Never seen it used with google forms.
First and foremost, thank you everyone who has responded with information thus far. None of the solutions posted here worked for my particular implementation (my implementation is probably to blame, it is very crude), but they definitely set me down the path to a working version of my form which we now lightly use. I have posted some of the code below:
function sheetFill(form, link) {
try {
var formResponses = form.namedValues;
var toForm = [0,0,0,0,0,0,0];
for (i=0;i < form.PartNumber.length;i++){
toForm[0] = toForm[0]+form.PartNumber[i];
}
... (several for loops later)
var d = new Date();
var ss = SpreadsheetApp.openById("IDHERE");
var sheet = ss.getCurrentSheet;
ss.appendRow([toForm[0], toForm[1], toForm[2], toForm[3], toForm[4], toForm[5], toForm[6], link, d]);
} catch(err) {
MailApp.sendEmail('EMAIL', 'doPost error', err+'\n\n'+JSON.stringify(form));
}
}
It is not very versatile or robust and isn't elegant, but it is a starting point.

end process in task manager while using javascript

This script works fine, but it keeps creating a new process in the task manager 'process' section. Not the Applications, just the Processes. I thought I was using the write 'quit' options but clearly not! This is the code:
<script>
function gbid(s) {
return document.getElementById(s);
}
function GetData(cell,row){
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("44227.xls");
var excel_sheet = excel.Worksheets("sheet1");
gbid('span1').innerText = excel_sheet.Cells(93,1).Value;
gbid('span2').innerText = excel_sheet.Cells(95,3).Value;
gbid('span3').innerText = excel_sheet.Cells(94,4).Value;
gbid('span4').innerText = excel_sheet.Cells(95,4).Value;
gbid('span5').innerText = excel_sheet.Cells(95,5).Value;
gbid('span6').innerText = excel_sheet.Cells(97,1).Value;
gbid('span7').innerText = excel_sheet.Cells(99,3).Value;
gbid('span8').innerText = excel_sheet.Cells(98,4).Value;
gbid('span9').innerText = excel_sheet.Cells(99,4).Value;
gbid('span10').innerText = excel_sheet.Cells(99,5).Value;
excel_file.Close();
excel.Application.Quit();
excel.Close();
}
</script>
<body onload="GetData();" />
The rest is just tables and such so no biggie. No significant code or anything. As you can see I've tried three different types of lines, and I've even tried them by themselves. NADA! I've even tried them without the ';' at the end! I've searched this site and used those examples but IT JUST WONT WORK! It'll keep creating new processes! Is it because I used:
new ActiveXObject("Excel.Application"); ?

JAWR i18n: unit testing javascript when using messages

Our application currently shares messages between the Java and Javascript side. They are stored as resource bundles in the class path, and we have a custom controller that returns all the messages as Json. The client side code look like this:
// This calls the controller to get all the messages
var messages = MessageBundle();
var text = messages.get('my.message', 1);
This is great because we can mock "messages" in our unit tests.
I want to start using JAWR for this, since we already use it for other things. The problem is JAWR generates the following Javascript object:
var text = messages.my.message(1);
This means the code cannot be unit tested anymore unless the unit tests also define a global "messages" variable with the right nested objects. Is there a way around this? Any idea how to extend JAWR to make this unit-testable?
Currently my work around is:
function messages() {
var args = Array.prototype.slice.call(arguments);
var messageId = args.shift();
var messageFunc = window.messages;
messageId.split('.').forEach(function(part) {
messageFunc = messageFunc[part];
});
return messageFunc(args);
}
// Same syntax as the old one, but uses the JAWR object behind the scenes
// This function is easy to mock for a unit test
var text = messages('my.message', 1);
Thanks for any ideas!
Maybe next samples can help you.
1)
function messagesTester(funcPath,id) {
var args=funcPath.split('.'),root=window.messages;
for(var i=0;i<args.length;i++)root=root[args[i]];
return root(id);
// or if more that one parameter for *func*, then, for example:
// return root.apply(null,Array.prototype.slice(arguments,1));
}
var text = messagesTester('my.message',1);
2)
function messagesTester(funcPath) {
var args=funcPath.split('.'),root=window.messages;
for(var i=0;i<args.length;i++)root=root[args[i]];
return root;
}
// var text = messagesTester('my.message')( /*arguments list*/ );
var text = messagesTester('my.message')(1);

Categories

Resources